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

public class railroad_va_shuffle {
	public static void main(String[] args) {
		new railroad_va_shuffle().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());
	}

	ArrayList<Integer>[] ind;
	ArrayList<Integer> ans;
	int now = 0;
	boolean[] was;
	int count = 0;
	int touch = -1;
	Random rnd = new Random(239);

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

	public int get(int ind) {
		return ind == touch ? 1 : (touch != -1 ? ans.get(ind > touch ? ind - 1
				: ind) + 1 : ans.get(ind));
	}

	public boolean check(int u) {
		int gcd = get(ind[u].get(0));
		for (int id : ind[u]) {
			gcd = gcd(gcd, get(id));
		}
		return (gcd == 1);
	}

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

		ind = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			ind[i] = new ArrayList<Integer>();
		}

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

		int start = -1;
		for (int i = 0; i < n; i++) {
			if (ind[i].size() == 1) {
				if (start == -1) {
					start = i;
				} else {
					out.println("IMPOSSIBLE");
					return;
				}
			}
		}

		ans = new ArrayList<Integer>();
		for (int i = 1; i < m; i++) {
			ans.add(i);
		}

		was = new boolean[n];
		if (start > 0) {
			touch = ind[start].get(0);
		} else {
			ans.add(m);
		}

		for (int i = 0; i < 100; i++) {
			boolean good = true;
			Collections.shuffle(ans, rnd);
			for (int j = 0; good && j < n; j++) {
				good &= check(j);
			}

			if (good) {
				for (int j = 0; j < m; j++) {
					out.println(get(j));
				}
				return;
			}
		}

		out.println("IMPOSSIBLE");
	}

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

			solve();

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