Problem: You are given a directed graph with n vertices and m directed edges without self-loops or multiple edges.

Let's denote the k-coloring of a digraph as following: you color each edge in one of k colors. The k-coloring is good if and only if there no cycle formed by edges of same color.

Find a good k-coloring of given digraph with minimum possible k.

Input

The first line contains two integers n and m (2 ≤ n ≤ 5000, 1 ≤ m ≤ 5000) — the number of vertices and edges in the digraph, respectively.

Next m lines contain description of edges — one per line. Each edge is a pair of integers u and v (1 ≤ u, v ≤ n, u ≠ v) — there is directed edge from u to v in the graph.

It is guaranteed that each ordered pair (u, v) appears in the list of edges at most once.

Output

In the first line print single integer k — the number of used colors in a good k-coloring of given graph.

In the second line print m integers c_1, c_2, ..., c_m (1 ≤ c_i ≤ k), where c_i is a color of the i-th edge (in order as they are given in the input).

If there are multiple answers print any of them (you still have to minimize k).

Examples

Input


4 5
1 2
1 3
3 4
2 4
1 4


Output


1
1 1 1 1 1 


Input


3 3
1 2
2 3
3 1


Output


2
1 1 2 

Solution (in JAVA):

Solution:
import java.util.*;
import java.io.*;
import java.text.*;

public class D1217 {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt(), m = sc.nextInt();

		Pair[] arr = new Pair[m];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = new Pair(sc.nextInt(), sc.nextInt());
		}
		int[] color = new int[m];
		int k = 1;
		while (true) {
			HashSet<Integer> reachablefrom[] = new HashSet[n];
			HashSet<Integer> canreach[] = new HashSet[n];
			for (int i = 0; i < canreach.length; i++) {
				reachablefrom[i] = new HashSet<Integer>();
				canreach[i] = new HashSet<Integer>();
			}
			boolean f = false;
			for (int i = 0; i < m; i++) {
				if (color[i] != 0) {
					continue;
				}
				if (reachablefrom[arr[i].y].contains(arr[i].x))
					continue;
				else {
					color[i] = k;
					canreach[arr[i].y].add(arr[i].x);
					reachablefrom[arr[i].x].add(arr[i].y);
					for (int x : canreach[arr[i].x]) {
						canreach[arr[i].y].add(x);
						reachablefrom[x].add(arr[i].y);
					}
					for (int x : reachablefrom[arr[i].y]) {
						reachablefrom[arr[i].x].add(x);
						canreach[x].add(arr[i].x);
					}
					for (int u : canreach[arr[i].x]) {
						for (int v : reachablefrom[arr[i].y]) {
							reachablefrom[u].add(v);
							canreach[v].add(u);
						}
					}
				}
			}
			for (int i = 0; i < m; i++) {
				if (color[i] == 0)
					f = true;
			}
			if (!f)
				break;
			k++;
		}
		pw.println(k);
		for (int i = 0; i < m; i++)
			pw.print(color[i] + " ");
		pw.close();
	}

	static class Pair {
		int x, y;

		public Pair(int x, int y) {
			this.x = x - 1;
			this.y = y - 1;
		}
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(FileReader r) {
			br = new BufferedReader(r);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}