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.math.*;
import java.awt.*;
import java.util.*;
import java.io.*;
import java.util.ArrayList;



public class Main {
    public static void main(String[] args) throws Exception {
        /*new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    new Solver().solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "Solver", 1l << 30).start();*/

        new Solver().solve();
    }
}

class Solver {
    final Helper hp;
    final int MAXN = 1000_006;
    final long MOD = (long) 1e9 + 7;

    Solver() {
        hp = new Helper(MOD, MAXN);
        hp.initIO(System.in, System.out);
    }

    int N, M;
    ArrayList<Integer>[] graph;
    int[][] edges;

    int[][][] contains;

    void solve() throws Exception {
        int i, j, k;

        N = hp.nextInt(); M = hp.nextInt();
        graph = new ArrayList[N];
        for (i = 0; i < N; ++i) graph[i] = new ArrayList<>();
        edges = new int[M][];

        contains = new int[N + 7][N + 7][];

        for (i = 0; i < M; ++i) {
            edges[i] = new int[] {hp.nextInt() - 1, hp.nextInt() - 1, -7};
            contains[edges[i][0]][edges[i][1]] = edges[i];
        }

        //mem = new int[N + 7];
        hp.println(bs());
        for (int[] e : edges) hp.print(e[2] + " ");

        hp.flush();
    }

    int bs() {
        /*int l = 1, r = N;
        while (true) {
            int mid = l + r >> 1;
            if (l + 1 >= r) {
                if (tryWith(l)) return l;
                else if (!tryWith(r)) return r + 1;
                else return r;
            } else if (tryWith(mid)) r = mid;
            else l = mid + 1;
        }*/

        //System.out.println(tryWith(2));
        //return 1;
        if (tryWith(1)) return 1;

        for (int[] e : edges) {
            if (e[0] < e[1]) e[2] = 1;
            else e[2] = 2;
        }
        return 2;
        //System.out.println(tryWith(2));
        //return 1;
    }

    //int[] mem;
    Random rn = new Random();

    boolean tryWith(int colors) {
        //if (mem[colors] != 0) return mem[colors] == 1;
        int i, j, k;

        for (k = 0; k < (colors > 1 ? 17 : 1); ++k) {
            for (int[] ed : edges) {
                int[] oth = contains[ed[1]][ed[0]];
                if (oth == null) ed[2] = rn.nextInt(Integer.MAX_VALUE >> 2) % colors + 1;
                else if (ed[0] < ed[1]) {
                    int col1, col2;
                    do {
                        col1 = rn.nextInt(Integer.MAX_VALUE >> 2) % colors + 1;
                        col2 = rn.nextInt(Integer.MAX_VALUE >> 2) % colors + 1;
                    } while (colors > 1 && col1 == col2);
                    ed[2] = col1; oth[2] = col2;
                }
            }

            //for (int[] e : edges) System.out.print(e[2] + " ");

            boolean cycle = false;
            for (j = 1; j <= colors && !cycle; ++j) {
                for (int[] e : edges)
                    if (e[2] == j) {
                        graph[e[0]].add(e[1]);
                    }


                //for (i = 0; i < N; ++i) System.out.print(Arrays.toString(edges[i]));
                //System.out.println();

                HashSet<Integer> ws = new HashSet<>(), gs = new HashSet<>(), bs = new HashSet<>();
                for (i = 0; i < N; ++i) ws.add(i);
                while (!ws.isEmpty()) {
                    if (dfs(ws.iterator().next(), ws, gs, bs)) {
                        cycle = true;
                        break;
                    }
                }

                for (i = 0; i < N; ++i) graph[i].clear();
            }

            //System.out.println("Cycle: " + cycle);
            if (!cycle) return true;

        }

        //mem[colors] = -1;
        return false;
    }

    boolean dfs(int node, HashSet<Integer> w, HashSet<Integer> g, HashSet<Integer> b) {
        w.remove(node);
        g.add(node);

        for (int itr : graph[node]) {
            if (b.contains(itr)) continue;
            else if (g.contains(itr)) return true;
            else if (dfs(itr, w, g, b)) return true;
        }

        g.remove(node);
        b.add(node);
        return false;
    }
}

class Helper {
    final long MOD;
    final int MAXN;

    public Helper(long mod, int maxn) {
        MOD = mod;
        MAXN = maxn;
    }


    public static int[] sieve;
    public static ArrayList<Integer> primes;

    public void setSieve() {
        primes = new ArrayList<>();
        sieve = new int[MAXN];
        int i, j;
        for (i = 2; i < MAXN; ++i)
            if (sieve[i] == 0) {
                primes.add(i);
                for (j = i; j < MAXN; j += i) {
                    sieve[j] = i;
                }
            }
    }


    public static long[] factorial;

    public void setFactorial() {
        factorial = new long[MAXN];
        factorial[0] = 1;
        for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
    }

    public long getFact(int n) {
        if (factorial == null) setFactorial();
        return factorial[n];
    }

    public long ncr(int n, int r) {
        if (r > n) return 0;
        if (factorial == null) setFactorial();
        long numerator = factorial[n];
        long denominator = factorial[r] * factorial[n - r] % MOD;
        return numerator * pow(denominator, MOD - 2, MOD) % MOD;
    }


    public long[] getLongArray(int size) throws Exception {
        long[] ar = new long[size];
        for (int i = 0; i < size; ++i) ar[i] = nextLong();
        return ar;
    }

    public int[] getIntArray(int size) throws Exception {
        int[] ar = new int[size];
        for (int i = 0; i < size; ++i) ar[i] = nextInt();
        return ar;
    }

    public String[] getStringArray(int size) throws Exception {
        String[] ar = new String[size];
        for (int i = 0; i < size; ++i) ar[i] = next();
        return ar;
    }

    public String joinElements(long[] ar) {
        StringBuilder sb = new StringBuilder();
        for (long itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }


    public String joinElements(int[] ar) {
        StringBuilder sb = new StringBuilder();
        for (int itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(String[] ar) {
        StringBuilder sb = new StringBuilder();
        for (String itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }

    public String joinElements(Object[] ar) {
        StringBuilder sb = new StringBuilder();
        for (Object itr : ar) sb.append(itr).append(" ");
        return sb.toString().trim();
    }


    public long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }


    public long max(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public int max(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.max(ret, itr);
        return ret;
    }

    public long min(long[] ar) {
        long ret = ar[0];
        for (long itr : ar) ret = Math.min(ret, itr);
        return ret;
    }

    public int min(int[] ar) {
        int ret = ar[0];
        for (int itr : ar) ret = Math.min(ret, itr);
        return ret;
    }


    public long sum(long[] ar) {
        long sum = 0;
        for (long itr : ar) sum += itr;
        return sum;
    }

    public long sum(int[] ar) {
        long sum = 0;
        for (int itr : ar) sum += itr;
        return sum;
    }


    public long pow(long base, long exp, long MOD) {
        base %= MOD;
        long ret = 1;
        while (exp > 0) {
            if ((exp & 1) == 1) ret = ret * base % MOD;
            base = base * base % MOD;
            exp >>= 1;
        }
        return ret;
    }


    static byte[] buf = new byte[2048];
    static int index, total;
    static InputStream in;
    static BufferedWriter bw;


    public void initIO(InputStream is, OutputStream os) {
        try {
            in = is;
            bw = new BufferedWriter(new OutputStreamWriter(os));
        } catch (Exception e) {
        }
    }

    public void initIO(String inputFile, String outputFile) {
        try {
            in = new FileInputStream(inputFile);
            bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(outputFile)));
        } catch (Exception e) {
        }
    }

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

    public String next() throws Exception {
        int c;
        for (c = scan(); c <= 32; c = scan()) ;
        StringBuilder sb = new StringBuilder();
        for (; c > 32; c = scan())
            sb.append((char) c);
        return sb.toString();
    }

    public int nextInt() throws Exception {
        int c, val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public long nextLong() throws Exception {
        int c;
        long val = 0;
        for (c = scan(); c <= 32; c = scan()) ;
        boolean neg = c == '-';
        if (c == '-' || c == '+')
            c = scan();
        for (; c >= '0' && c <= '9'; c = scan())
            val = (val << 3) + (val << 1) + (c & 15);
        return neg ? -val : val;
    }

    public void print(Object a) throws Exception {
        bw.write(a.toString());
    }

    public void printsp(Object a) throws Exception {
        print(a);
        print(" ");
    }

    public void println() throws Exception {
        bw.write("\n");
    }

    public void println(Object a) throws Exception {
        print(a);
        println();
    }

    public void flush() throws Exception {
        bw.flush();
    }
}
