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 
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DColoringEdges solver = new DColoringEdges();
        solver.solve(1, in, out);
        out.close();
    }

    static class DColoringEdges {
        int[][][] G;
        boolean loop;
        boolean[] visited;
        boolean[] LOL;
        int[] ans;

        public void dfs(int node, int parent) {
            if (visited[node]) return;
            if (loop) return;
            visited[node] = true;
            LOL[node] = true;
            for (int[] i : G[node]) {
                if (visited[i[0]]) {
                    if (LOL[i[0]]) loop = true;
                    continue;
                }
                dfs(i[0], node);
            }
            LOL[node] = false;
        }

        public void dfs1(int node) {
            if (visited[node]) return;
            visited[node] = true;
            LOL[node] = true;
            for (int[] i : G[node]) {
                if (visited[i[0]]) {
                    if (LOL[i[0]]) ans[i[1]] = 2;
                    else ans[i[1]] = 1;
                    continue;
                }
                ans[i[1]] = 1;
                dfs1(i[0]);
            }
            LOL[node] = false;
        }

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int m = in.scanInt();
            int[] from = new int[m];
            int[] to = new int[m];
            int[] weight = new int[m];
            for (int i = 0; i < m; i++) {
                from[i] = in.scanInt();
                to[i] = in.scanInt();
                weight[i] = i;
            }
            G = CodeHash.packGraphWDirected(from, to, weight, n, m);
            loop = false;
            visited = new boolean[n + 1];
            LOL = new boolean[n + 1];
            for (int i = 1; i <= n; i++) dfs(i, -1);
            if (!loop) {
                out.println(1);
                for (int i = 1; i <= m; i++) out.print(1 + " ");
                return;
            }
            ans = new int[m];
            visited = new boolean[n + 1];
            LOL = new boolean[n + 1];
            for (int i = 1; i <= n; i++) dfs1(i);
            out.println(2);
            for (int i = 0; i < m; i++) out.print((ans[i]) + " ");
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }

    static class CodeHash {
        public static int[][][] packGraphWDirected(int[] from, int[] to, int[] w, int n, int m) {
            int[][][] g = new int[n + 1][][];
            int[] p = new int[n + 1];
            for (int i = 0; i < m; i++) p[from[i]]++;
            for (int i = 0; i <= n; i++) g[i] = new int[p[i]][2];
            for (int i = 0; i < from.length; i++) {
                --p[from[i]];
                g[from[i]][p[from[i]]][0] = to[i];
                g[from[i]][p[from[i]]][1] = w[i];
            }
            return g;
        }

    }
}

