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

public class railroad_vd {

	class Edge {
		int to;
		int num;

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

	int[] res;

	boolean[] was;

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

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

	void solve() throws IOException {
		int n = nextInt();
		edges = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			edges[i] = new ArrayList<Edge>();
		}
		int m = nextInt();
		int[] deg = new int[n];
		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));
			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;
		}
		was = new boolean[n];
		res = new int[m];
		dfs(root);
		for (int i = 0; i < n; i++) {
			if (!was[i]) {
				dfs(i);
			}
		}
		for (int i = 0; i < m; i++) {
			out.println(res[i]);
		}

	}

	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().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());
	}

}
