2 0
 100000 0
 8 9
1 2
2 3
3 4
4 1
5 6
6 7
7 8
8 5
6 8
 2 1
1 2
 11 9
5 9
8 5
11 3
11 1
3 4
7 11
3 1
11 2
7 2
 7 9
7 3
7 4
1 2
2 3
3 1
3 4
4 5
5 6
6 4
 7 5
5 4
7 3
7 1
6 7
3 1
 7 8
1 2
2 3
3 4
4 1
3 5
5 6
6 7
7 3
 6 9
1 2
2 3
1 4
4 2
5 2
5 3
4 5
6 4
6 5
 7 9
1 2
2 4
4 3
3 1
2 3
4 5
5 6
6 7
7 4
 1 0
 6 7
1 2
2 3
3 1
3 4
4 5
5 6
6 4
 4 5
1 2
2 3
3 4
4 1
1 3
 100000 3
99998 99999
99999 100000
100000 99998

0

 0

 4
1 2 3 4 
 0

 6
3 4 6 7 8 9 
 9
1 2 3 4 5 6 7 8 9 
 3
2 3 5 
 8
1 2 3 4 5 6 7 8 
 0

 4
6 7 8 9 
 0

 6
1 2 3 5 6 7 
 0

 3
1 2 3 

// practice with rainboy
import java.io.*;
import java.util.*;

public class CF962F {
	static ArrayList[] aa;
	static int[] hh, ii, jj, kk, dsu;
	static boolean[] back;
	static int find(int i) {
		return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i]));
	}
	static boolean join(int i, int j) {
		i = find(i);
		j = find(j);
		if (i == j)
			return false;
		if (dsu[i] > dsu[j]) {
			dsu[i] = j;
			kk[j] += kk[i];
		} else {
			if (dsu[i] == dsu[j])
				dsu[i]--;
			dsu[j] = i;
			kk[i] += kk[j];
		}
		return true;
	}
	static void dfs1(int h_, int i) {
		if (hh[i] != -1) {
			jj[h_] = i ^ ii[h_] ^ jj[h_];
			ii[h_] = i;
			kk[h_] = 1;
			back[h_] = true;
			return;
		}
		hh[i] = h_;
		ArrayList<Integer> adj = aa[i];
		for (int h : adj)
			if (h != h_ && !back[h]) {
				int j = i ^ ii[h] ^ jj[h];
				dfs1(h, j);
			}
	}
	static void dfs2(int h_, int i) {
		ArrayList<Integer> adj = aa[i];
		for (int h : adj)
			if (h != h_ && back[h] && i == ii[h]) {
				int j = jj[h];
				while (j != i) {
					int h1 = hh[j];
					if (!join(h, h1))
						break;
					j ^= ii[h1] ^ jj[h1];
				}
			}
		for (int h : adj)
			if (h != h_ && !back[h]) {
				int j = i ^ ii[h] ^ jj[h];
				dfs2(h, j);
			}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		aa = new ArrayList[n];
		for (int i = 0; i < n; i++)
			aa[i] = new ArrayList<Integer>();
		hh = new int[n];
		Arrays.fill(hh, -1);
		ii = new int[m];
		jj = new int[m];
		kk = new int[m];
		dsu = new int[m];
		Arrays.fill(dsu, -1);
		back = new boolean[m];
		for (int h = 0; h < m; h++) {
			st = new StringTokenizer(br.readLine());
			int i = Integer.parseInt(st.nextToken()) - 1;
			int j = Integer.parseInt(st.nextToken()) - 1;
			ii[h] = i;
			jj[h] = j;
			aa[i].add(h);
			aa[j].add(h);
		}
		for (int i = 0; i < n; i++)
			if (hh[i] == -1)
				dfs1(-2, i);
		for (int i = 0; i < n; i++)
			if (hh[i] == -2)
				dfs2(-2, 0);
		int[] ans = new int[m];
		int cnt = 0;
		for (int h = 0; h < m; h++)
			if (kk[find(h)] == 1)
				ans[cnt++] = h;
		pw.println(cnt);
		for (int h = 0; h < cnt; h++)
			pw.print(ans[h] + 1 + " ");
		pw.println();
		pw.close();
	}
}
