import java.io.*;
import java.util.*;

public class railroad_vd_wa3 {

	int gcd(int a, int b) {
		if (b == 0) {
			return a;
		} else {
			return gcd(b, a % b);
		}
	}

	class Edge {
		int to;
		int num;

		public Edge(int to, int num) {
			super();
			this.to = to;
			this.num = num;
		}
	}

	int[] res;

	ArrayList<Edge>[] edges;
	int num = 1;

	void update(int v) {
		for (int i = 0; i < edges[v].size(); i++) {
			Edge e = edges[v].get(i);
			if (res[e.num] == 0) {
				res[e.num] = num++;
			}
		}
	}

	int[] deg;

	void solve() throws IOException {
		long tm = System.currentTimeMillis();
		int n = nextInt();
		deg = new int[n];
		edges = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			edges[i] = new ArrayList<Edge>();
		}
		int m = nextInt();
		int[][] a = new int[m][2];
		for (int i = 0; i < m; i++) {
			int v1 = nextInt() - 1;
			int v2 = nextInt() - 1;
			edges[v1].add(new Edge(v2, i));
			edges[v2].add(new Edge(v1, i));
			a[i][0] = v1;
			a[i][1] = v2;
			deg[v1]++;
			deg[v2]++;
		}

		int c = 0;
		int root = 0;
		for (int i = 0; i < n; i++) {
			if (deg[i] == 1) {
				c++;
				root = i;
			}
		}
		if (c > 1) {
			out.println("IMPOSSIBLE");
			return;
		}
		Integer[] ord = new Integer[n];
		for (int i = 0; i < n; i++) {
			ord[i] = i;
		}
		Arrays.sort(ord, 0, n, new Comparator<Integer>() {
			public int compare(Integer o1, Integer o2) {
				if (deg[o1] == deg[o2]) {
					return o1 - o2;
				}
				return deg[o1] - deg[o2];
			}
		});

		while (System.currentTimeMillis() - tm < 5700) {
			num = 1;
			res = new int[m];
			for (int i = 0; i < n; i++) {
				Collections.shuffle(edges[i]);
			}
			if (c == 1) {
				update(root);
			}
			for (int i = 0; i < n; i++) {
				update(ord[i]);
			}

			int[] vgcd = new int[n];
			for (int i = 0; i < m; i++) {
				vgcd[a[i][0]] = gcd(vgcd[a[i][0]], res[i]);
				vgcd[a[i][1]] = gcd(vgcd[a[i][1]], res[i]);
			}
			boolean fl = true;
			for (int i = 0; i < n; i++) {
				fl = fl & (vgcd[i] == 1);
			}
			if (fl || System.currentTimeMillis() - tm > 5400) {
				for (int i = 0; i < m; i++) {
					out.println(res[i]);
				}
				return;
			}
		}
	}

	public void run() throws IOException {
		br = new BufferedReader(new FileReader("railroad.in"));
		out = new PrintWriter("railroad.out");
		solve();
		br.close();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new railroad_vd_wa3().run();
	}

	BufferedReader br;
	StringTokenizer str;
	PrintWriter out;

	String next() throws IOException {
		while (str == null || !str.hasMoreTokens()) {
			String s = br.readLine();
			if (s != null) {
				str = new StringTokenizer(s);
			} else {
				return null;
			}
		}
		return str.nextToken();
	}

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

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

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

}
