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.util.*;
public class Main {
	static BufferedReader br;
	static PrintWriter pr;
	static int cin() throws Exception
	{
		return Integer.valueOf(br.readLine());
	}
	static int[] split() throws Exception
	{
		String[] cmd=br.readLine().split(" ");
		int[] ans=new int[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Integer.valueOf(cmd[i]);
		}
		return ans;
	}
	static long[] splitL() throws IOException
	{
		String[] cmd=br.readLine().split(" ");
		long[] ans=new long[cmd.length];
		for(int i=0;i<cmd.length;i++)
		{
			ans[i]=Long.valueOf(cmd[i]);
		}
		return ans;
	}
	static int sum(long n)
	{
		int ans=0;
		while(n!=0)
		{
			ans=ans+(int)(n%10);
			n=n/10;
		}
		return ans;
	}
	static int gcd(int x,int y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		if(x>y)
			return gcd(x%y,y);
		else
			return gcd(x,y%x);
	}
	static int[]par;
	static int[]rank;
	static boolean union(int x,int y)
	{
	    int p1=find(x);
	    int p2=find(y);
	    if(p1==p2)
	    return true;
	    if(rank[p1]>rank[p2])
	    par[p2]=p1;
	    else
	    {
	        par[p1]=p2;
	        if(rank[p1]==rank[p2])
	        rank[p2]++;
	    }
	    return false;
	}
	static int find(int x)
	{
	    if(x==par[x])
	    return x;
	    return par[x]=find(par[x]);
	}
	static ArrayList<Integer>[]gr;
	static int n;
	static int[]indeg;
	static boolean check()
	{
	    Queue<Integer>q=new LinkedList<>();
	    int cnt=0;
	    int[]dup=new int[n+1];
	    for(int i=0;i<=n;i++)
	    {
	        dup[i]=indeg[i];
	    }
	    for(int i=1;i<=n;i++)
	    {
	        if(dup[i]==0)
	        {
	            cnt++;
	            q.add(i);
	        }
	    }
	    if(q.size()==0)
	    return false;
	    while(q.size()!=0)
	    {
	        int node=q.poll();
	        for(int i=0;i<gr[node].size();i++)
	        {
	            int y=gr[node].get(i);
	            dup[y]--;
	            if(dup[y]==0)
	            {
	                cnt++;
	                q.add(y);
	            }
	        }
	    }
	    if(cnt!=n)
	    return false;
	    return true;
	}
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		br=new BufferedReader(new InputStreamReader(System.in));
		pr=new PrintWriter(new OutputStreamWriter(System.out));
		int cases=1;
		while(cases!=0)
		{
			cases--;
			int[]ar=split();
			n=ar[0];
			int m=ar[1];
			int[]ans=new int[m];
			par=new int[n+1];
			for(int i=1;i<=n;i++)
			{
			    par[i]=i;
			}
			rank=new int[n+1];
			int cnt=1;
			int[][]edges=new int[m][2];
			gr=new ArrayList[n+1];
			for(int i=0;i<=n;i++)
			{
			    gr[i]=new ArrayList<>();
			}
			indeg=new int[n+1];
			for(int i=0;i<m;i++)
			{
			    ar=split();
			    edges[i]=ar;
			    indeg[ar[1]]++;
			    gr[ar[0]].add(ar[1]);
			}
			if(check())
			{
			    System.out.println(1);
			    for(int i=0;i<m;i++)
			    {
			        System.out.print(1+" ");
			    }
			    System.out.println();
			    continue;
			}
			gr=new ArrayList[n+1];
			for(int i=0;i<=n;i++)
			{
			    gr[i]=new ArrayList<>();
			}
			indeg=new int[n+1];
			for(int i=0;i<m;i++)
			{
			    int x=edges[i][0];
			    int y=edges[i][1];
			    indeg[y]++;
			    gr[x].add(y);
			    if(check())
			    {
			        ans[i]=1;
			    }
			    else
			    {
			        gr[x].remove(new Integer(y));
			        indeg[y]--;
			        ans[i]=2;
			    }
			}
			System.out.println(2);
			for(int i=0;i<m;i++)
			{
			    System.out.print(ans[i]+" ");
			}
			System.out.println();
		}
	}
}