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

public class railroad_vd_wa2 {

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

	void solve() throws IOException {
		long tm = System.currentTimeMillis();
		int n = nextInt();
		int m = nextInt();
		int[][] a = new int[m][2];
		int[] deg = new int[n];
		for (int i = 0; i < m; i++) {
			a[i][0] = nextInt() - 1;
			a[i][1] = nextInt() - 1;
			deg[a[i][0]]++;
			deg[a[i][1]]++;
		}
		int root = -1;
		for (int i = 0; i < n; i++) {
			if (deg[i] == 1) {
				root = i;
			}
		}
		ArrayList<Integer> res = new ArrayList<Integer>();
		for (int i = 0; i < m; i++) {
			res.add(i + 1);
		}
		while (System.currentTimeMillis() - tm < 5700) {
			Collections.shuffle(res);
			if (root != -1) {
				int p1 = -1;
				int p2 = -1;
				for (int i = 0; i < res.size(); i++) {
					if (res.get(i) == 1) {
						p1 = i;
					}
					if (deg[a[i][0]] == 1 || deg[a[i][1]] == 1) {
						p2 = i;
					}
				}
				int t = res.get(p1);
				res.set(p1, res.get(p2));
				res.set(p2, t);
			}

			int[] vgcd = new int[n];
			for (int i = 0; i < m; i++) {
				vgcd[a[i][0]] = gcd(vgcd[a[i][0]], res.get(i));
				vgcd[a[i][1]] = gcd(vgcd[a[i][1]], res.get(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 : res) {
					out.println(i);
				}
				return;
			}
		}
		out.println("IMPOSSIBLE");
	}

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

}
