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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Vector;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DColoringEdges solver = new DColoringEdges();
        solver.solve(1, in, out);
        out.close();
    }

    static class DColoringEdges {
        Vector<Integer>[] a = new Vector[5456];

        public void solve(int testNumber, InputReader in, OutputWriter out) {

            int n = in.nextInt();

            int m = in.nextInt();

            for (int i = 1; i <= n; i++) {
                a[i] = new Vector<>();
            }

            pair<Integer, Integer, Integer>[] ans = new pair[m];

            for (int i = 0; i < m; i++) {
                int x, y;
                x = in.nextInt();
                y = in.nextInt();

                ans[i] = new pair(x, y, i);

                a[x].add(y);
            }

            boolean flag = cycle(n);

            // out.println(flag);
            int[] res = new int[m];
            Arrays.fill(res, 1);

            if (flag == false) {
                out.println(1);
                for (int i : res) {
                    out.print(i + " ");
                }
                return;
            }

            for (int i = 0; i < m; i++) {
                if (ans[i].getFi() > ans[i].getSe()) {
                    res[ans[i].getTh()] = 2;
                }
            }
            out.println(2);
            for (int i : res) {
                out.print(i + " ");
            }


        }

        private boolean dfs(int s, int[] color) {
            color[s] = 1;

            for (int j : a[s]) {
                if (color[j] == 1) {
                    return true;
                }

                if (color[j] == 0 && dfs(j, color)) {
                    return true;
                }
            }

            color[s] = 2;
            return false;
        }

        private boolean cycle(int n) {

            int[] color = new int[n + 1];

            Arrays.fill(color, 0);

            for (int i = 1; i <= n; i++) {
                if (color[i] == 0) {
                    if (dfs(i, color)) {
                        return true;
                    }
                }
            }
            return false;
        }

        class pair<T, W, X> implements Comparable<pair> {
            private T fi;
            private W se;
            private X th;

            public pair() {

            }

            public pair(T fi, W se, X th) {
                this.fi = fi;
                this.th = th;
                this.se = se;
            }

            public T getFi() {
                return fi;
            }

            public W getSe() {
                return se;
            }

            public X getTh() {
                return th;
            }

            public int compareTo(pair o) {
                return 0;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }
}