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 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeSet;

/*


5 6
1 2
2 3
3 1
1 4
4 5
5 1

11 13
1 2
2 3
3 1
1 5
5 6
6 7
7 5
7 8
8 9
9 5
9 10
10 11
11 9

5 10
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5

10 3
9 10
10 8
8 9

 */
public class pizza implements Runnable{
	public static void main(String[] args) throws IOException {
		new Thread(null, new pizza(), "", 1<<28).start();
	}
	public void run() {
		try {
		FastScanner in = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt(), m = in.nextInt();
		MagicComponents g = new MagicComponents(n);
		for (int i = 0; i < m; i++) {
			int u = in.nextInt() - 1, v = in.nextInt() - 1;
			g.addEdge(u, v);
		}
		g.run();
		int[] ids = new int[n];
		int ID = 0;
		ArrayList<Edge> res = new ArrayList<>();
		for (ArrayList<Edge> bcc : g.bccs) {
			if (bcc.size() == 1)
				continue;
			ID++;
			int nodeCount = 0;
			for (Edge e : bcc) {
				if (ids[e.u] != ID) {
					ids[e.u] = ID;
					nodeCount++;
				}
				if (ids[e.v] != ID) {
					ids[e.v] = ID;
					nodeCount++;
				}
			}
			int edgeCount = bcc.size();
			if (nodeCount == edgeCount) {
				res.addAll(bcc);
			}
		}
		Collections.sort(res, Comparator.comparing(a -> a.id));
		out.println(res.size());
		for (int i = 0; i < res.size(); i++) {
			if (i != 0)
				out.print(' ');
			out.print(res.get(i).id + 1);
		}
		out.println();
		out.close();
		} catch(Throwable t) {
			t.printStackTrace();
			System.exit(1);
		}
	}

	static class Edge {
		int u, v, id;

		public Edge(int U, int V, int i) {
			u = U;
			v = V;
			id = i;
		}
	}

	static class MagicComponents {
		int num, n, edges;
		int[] dfsNum, low, vis;
		ArrayList<Edge> adj[];
		ArrayList<ArrayList<Edge>> bccs;
		ArrayDeque<Edge> eStack;

		MagicComponents(int N) {
			adj = new ArrayList[n = N];
			for (int i = 0; i < n; i++)
				adj[i] = new ArrayList<>();
			edges = 0;
		}

		void addEdge(int u, int v) {
			adj[u].add(new Edge(u, v, edges));
			adj[v].add(new Edge(v, u, edges++));
		}

		void run() {
			vis = new int[n];
			dfsNum = new int[n];
			low = new int[n];
			bccs = new ArrayList<>();
			eStack = new ArrayDeque<>();
			num = 0;

			for (int i = 0; i < n; i++) {
				if (vis[i] != 0)
					continue;
				dfs(i, -1);
			}
		}

		void dfs(int node, int par) {
			dfsNum[node] = low[node] = num++;
			vis[node] = 1;
			for (Edge e : adj[node]) {
				if (e.v == par)
					continue;
				if (vis[e.v] == 0) {
					eStack.push(e);
					dfs(e.v, node);
					low[node] = Math.min(low[node], low[e.v]);
					if (low[e.v] >= dfsNum[node]) {
						if (low[e.v] > dfsNum[node]) {
							pop(node);
						} else
							pop(node);
					}
				} else if (vis[e.v] == 1) {
					low[node] = Math.min(low[node], dfsNum[e.v]);
					eStack.push(e);
				}
			}
			vis[node] = 2;
		}

		void pop(int u) {
			ArrayList<Edge> list = new ArrayList<>();
			for (;;) {
				Edge e = eStack.pop();
				list.add(e);
				if (e.u == u)
					break;
			}
			bccs.add(list);
		}
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(InputStream i) {
			br = new BufferedReader(new InputStreamReader(i));
			st = null;
		}

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

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

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

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