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

public class railroad_va_nullpointer {
	public static void main(String[] args) {
		new railroad_va_nullpointer().run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

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

	public class Edge {
		int u, v, ind;

		public Edge(int u, int v, int ind) {
			this.u = u;
			this.v = v;
			this.ind = ind;
		}
	}

	ArrayList<Edge>[] e;
	int[] ans;
	int now = 0;
	boolean[] was;
	int count = 0;

	public void dfs(int u) {
		was[u] = true;
		for (Edge edge : e[u]) {
			if (ans[edge.ind] == 0) {
				ans[edge.ind] = ++now;
			}
			if (!was[edge.v]) {
				dfs(edge.v);

			}
		}
	}

	public void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();

		e = new ArrayList[n];
		ans = new int[m];
		for (int i = 0; i < n; i++) {
			e[i] = new ArrayList<Edge>();
		}

		for (int i = 0; i < m; i++) {
			int u = nextInt() - 1;
			int v = nextInt() - 1;
			e[u].add(new Edge(u, v, i));
			e[v].add(new Edge(v, u, i));
		}

		int start = -1;
		for (int i = 0; i < n; i++) {
			if (e[i].size() == 1) {
				if (start == -1) {
					start = i;
				} else {
					out.println("IMPOSSIBLE");
					return;
				}
			}
		}
		
		was = new boolean[n];
		if (start > 0)
			dfs(start);
		
		for (int i = 0; i < n; i++) {
			if (!was[i])
				dfs(i);
		}

		for (int i = 0; i < m; i++) {
			out.println(ans[i]);
		}
	}

	public void run() {
		try {
			br = new BufferedReader(new FileReader("railroad.in"));
			out = new PrintWriter("railroad.out");

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
