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

public class railroad_av {

	FastScanner in;
	PrintWriter out;
	final String fileName = "railroad".toLowerCase();
	
	void solve() {
		final int n = in.nextInt();
		final int m = in.nextInt();
		final List<Edge>[] graph = new List[n];
		for (int i = 0; i < n; i++) {
			graph[i] = new ArrayList<>();
		}
		
		for (int i = 0; i < m; i++) {
			int from = in.nextInt() - 1;
			int to = in.nextInt() - 1;
			graph[from].add(new Edge(from, to, i));
			graph[to].add(new Edge(to, from, i));
		}
		
		int root = -1;
		for (int i = 0;  i < n; i++) {
			if (graph[i].size() == 1) {
				if (root == -1) {
					root = i;
				} else {
					out.println("IMPOSSIBLE");
					return;
				}
			}
		}
		
		if (root == -1) {
			root = 0;
		}
		
		final int[] ans = new int[m];
		
		class DFSActor {
			final private boolean[] used;
			private int counter;
			public DFSActor(int n, int root) {
				used = new boolean[n];
				dfs(root);
				counter = 1;
			}
			
			private void dfs(int u) {
				used[u] = true;
				for (Edge e : graph[u]) {
					if (ans[e.id] == 0) {
						ans[e.id] = counter++;
					}
					
					if (!used[e.to]) {
						dfs(e.to);
					}
				}
			}
		}
		
		new DFSActor(n, root);
		
		for (int i : ans) {
			out.println(i);
		}
	}

	class Edge {
		int from, to, id;

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

	void run() {
		try {
			in = new FastScanner(fileName + ".in");
			out = new PrintWriter(fileName + ".out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

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