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.util.*;

public class SimpleCycleEdges {
	
	//holds the indexes of edges
	static HashMap<String, Integer> map = new HashMap<String, Integer>();
	
	//true if edge i is a bridge
	static boolean[] bridge;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		bridge = new boolean[m];
		Pair[] e = new Pair[m];
		Graph g1 = new Graph(n);
		for(int i = 0; i < m; i++) {
			int u = scan.nextInt()-1;
			int v = scan.nextInt()-1;
			e[i] = new Pair(u, v);
			map.put(u+"-"+v, i);
			map.put(v+"-"+u, i);
			g1.addEdge(u, v);
		}
		g1.bridge();
		
		//Make a new graph, without the bridges
		Graph g2 = new Graph(n);
		for(int i = 0; i < m; i++) {
			if(!bridge[i]) {
				int u = e[i].a;
				int v = e[i].b;
				g2.addEdge(u, v);
			}
		}
		
		boolean[] v = new boolean[n];
		PriorityQueue<Integer> idx = new PriorityQueue<Integer>();
		
		//Find the connected components, count edges
		//If edges == vertices, those are part of the answer
		for(int i = 0; i < n; i++) {
			if(v[i]) continue;
			
			int numV = 0;
			int numE = 0;
			HashSet<Integer> edges = new HashSet<Integer>();
			ArrayDeque<Integer> bfs = new ArrayDeque<Integer>();
			bfs.add(i);
			v[i] = true;
			
			while(!bfs.isEmpty()) {
				int x = bfs.poll();
				numV++;
				for(int j = 0; j < g2.adj[x].size(); j++) {
					int next = g2.adj[x].get(j);
					
					if(!v[next]) {
						bfs.add(next);
						v[next] = true;
					}
					
					int edgeIdx = map.get(x+"-"+next);
					edges.add(edgeIdx);
				}
			}
			
			numE = edges.size();
			
			if(numV == numE) {
				for(Integer j : edges) {
					idx.add(j);
				}
			}
		}
		
		System.out.println(idx.size());
		while(idx.size() > 0) System.out.print((idx.poll()+1)+" ");
		System.out.println();
		
	}
	
	static class Pair{
		
		int a;
		int b;
		
		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}

	static class Graph{

		private int V;   // No. of vertices

		// Array of lists for Adjacency List Representation
		private LinkedList<Integer> adj[];
		int time = 0;
		static final int NIL = -1;
		
		boolean[] vis;

		// Constructor
		Graph(int v){
			V = v;
			vis = new boolean[v];
			adj = new LinkedList[v];
			for (int i=0; i<v; ++i)
				adj[i] = new LinkedList();
		}

		// Function to add an edge into the graph
		void addEdge(int v, int w) {
			adj[v].add(w);  // Add w to v's list.
			adj[w].add(v);  //Add v to w's list
		}

		// A recursive function that finds and prints bridges
		// using DFS traversal
		// u --> The vertex to be visited next
		// visited[] --> keeps tract of visited vertices
		// disc[] --> Stores discovery times of visited vertices
		// parent[] --> Stores parent vertices in DFS tree
		void bridgeUtil(int u, boolean visited[], int disc[],
				int low[], int parent[]){
			// Mark the current node as visited
			visited[u] = true;
			// Initialize discovery time and low value
			disc[u] = low[u] = ++time;
			// Go through all vertices adjacent to this
			Iterator<Integer> i = adj[u].iterator();
			while (i.hasNext()){
				int v = i.next();  // v is current adjacent of u
				// If v is not visited yet, then make it a child
				// of u in DFS tree and recur for it.
				// If v is not visited yet, then recur for it
				if (!visited[v]){
					parent[v] = u;
					bridgeUtil(v, visited, disc, low, parent);
					// Check if the subtree rooted with v has a
					// connection to one of the ancestors of u
					low[u]  = Math.min(low[u], low[v]);
					// If the lowest vertex reachable from subtree
					// under v is below u in DFS tree, then u-v is
					// a bridge
					if (low[v] > disc[u]) {
						int j = map.get(u+"-"+v);
						bridge[j] = true;
					}
				}
				// Update low value of u for parent function calls.
				else if (v != parent[u])
					low[u]  = Math.min(low[u], disc[v]);
			}
		}
		
		// DFS based function to find all bridges. It uses recursive
		// function bridgeUtil()
		void bridge(){
			// Mark all the vertices as not visited
			boolean visited[] = new boolean[V];
			int disc[] = new int[V];
			int low[] = new int[V];
			int parent[] = new int[V];
			// Initialize parent and visited, and ap(articulation point)
			// arrays
			for (int i = 0; i < V; i++){
				parent[i] = NIL;
				visited[i] = false;
			}
			// Call the recursive helper function to find Bridges
			// in DFS tree rooted with vertex 'i'
			for (int i = 0; i < V; i++)
				if (visited[i] == false)
					bridgeUtil(i, visited, disc, low, parent);
		}
	}
}
