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.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

public class P1217D {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int m = scanner.nextInt();
        List<List<Integer>> links = new ArrayList<>(n);
        for (int i = 0; i < n; ++i)
            links.add(new LinkedList<>());
        int[] inDegree = new int[n];
        int[][] arcs = new int[m][2];
        for (int i = 0; i < m; ++i) {
            arcs[i][0] = scanner.nextInt() - 1;
            arcs[i][1] = scanner.nextInt() - 1;
            links.get(arcs[i][0]).add(i);
            ++inDegree[arcs[i][1]];
        }
        int[] color = new int[m];
        int[] visited = new int[n];
//        for (int i = 0; i < n; ++i) {
//            if (inDegree[i] == 0) {
//                dfs(i, links, arcs, visited, color);
//            }
//        }
        for (int i = 0; i < n; ++i)
            if (visited[i] == 0)
                dfs(i, links, arcs, visited, color);
        int max = 0;
        for (int i = 0; i < m; ++i)
            max = Math.max(color[i], max);
        writer.println(max);
        for (int i = 0; i < m; ++i)
            writer.print(color[i] + " ");
        writer.close();
    }

    private static void dfs(int u, List<List<Integer>> links, int[][] arcs, int[] visited, int[] ans) {
        visited[u] = 1;
        for (int idx : links.get(u)) {
            int v = arcs[idx][1];
            if (visited[v] == 0) {
                ans[idx] = 1;
                dfs(v, links, arcs, visited, ans);
            } else if (visited[v] == 1) {
                ans[idx] = 2;
            } else {
                ans[idx] = 1;
            }
        }
        visited[u] = 2;
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        private SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}