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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Atharva Nagarkar
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FSimpleCyclesEdges solver = new FSimpleCyclesEdges();
        solver.solve(1, in, out);
        out.close();
    }

    static class FSimpleCyclesEdges {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            MagicComponents mc = new MagicComponents(n);
            int[] indeg = new int[n];
            for (int i = 0; i < m; ++i) {
                Edge e = new Edge(in.nextInt() - 1, in.nextInt() - 1, i);
                mc.addEdge(e.u, e.v);
                indeg[e.u]++;
                indeg[e.v]++;
            }
            mc.run();
            boolean[] bridge = new boolean[m];
            for (Edge e : mc.bridges) {
                bridge[e.id] = true;
                indeg[e.u]--;
                indeg[e.v]--;
            }
            DSU dsu = new DSU(n);
            for (int i = 0; i < n; ++i) {
                for (Edge e : mc.adj[i]) {
                    if (bridge[e.id]) continue;
                    dsu.union(e.u, e.v);
                }
            }
            HashMap<Integer, ArrayList<Integer>> comps = new HashMap<>();
            for (int i = 0; i < n; ++i) {
                if (!comps.containsKey(dsu.get(i))) comps.put(dsu.get(i), new ArrayList<>());
                comps.get(dsu.get(i)).add(i);
            }
            boolean[] valid = new boolean[m];
            for (ArrayList<Integer> comp : comps.values()) {
                boolean good = true;
                for (int i : comp) {
                    if (indeg[i] != 2) {
                        good = false;
                        break;
                    }
                }
                if (good) {
                    for (int i : comp) {
                        for (Edge e : mc.adj[i]) {
                            if (!bridge[e.id]) valid[e.id] = true;
                        }
                    }
                }
            }
            int ans = 0;
            for (boolean b : valid) if (b) ++ans;
            out.println(ans);
            for (int i = 0; i < m; ++i) if (valid[i]) out.print((i + 1) + " ");
            out.println();
        }

        class Edge {
            public int u;
            public int v;
            public int id;

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

        }

        class MagicComponents {
            int num;
            int n;
            int edges;
            int[] dfsNum;
            int[] low;
            int[] vis;
            public ArrayList<Integer> cuts;
            public ArrayList<Edge> bridges;
            public ArrayList<Edge>[] adj;
            public ArrayList<ArrayList<Edge>> bccs;
            ArrayDeque<Edge> eStack;

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

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

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

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

            private void dfs(int node, int par) {
                dfsNum[node] = low[node] = num++;
                vis[node] = 1;
                int nChild = 0;
                for (Edge e : adj[node]) {
                    if (e.v == par) continue;
                    if (vis[e.v] == 0) {
                        ++nChild;
                        eStack.push(e);
                        dfs(e.v, node);
                        low[node] = Math.min(low[node], low[e.v]);
                        if (low[e.v] >= dfsNum[node]) {
                            if (dfsNum[node] > 0 || nChild > 1)
                                cuts.add(node);
                            if (low[e.v] > dfsNum[node]) {
                                bridges.add(e);
                                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;
            }

            private 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 InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }

    static class DSU {
        public int[] id;
        public int size;

        public DSU(int x) {
            size = x;
            id = new int[size];
            for (int i = 0; i < size; ++i) {
                id[i] = i;
            }
        }

        public int get(int a) {
            return id[a] == a ? a : (id[a] = get(id[a]));
        }

        public void union(int a, int b) {
            int x = Math.min(a, b);
            int y = Math.max(a, b);
            a = y;
            b = x;
            if (get(a) == get(b)) return;
            id[get(a)] = id[get(b)];
            --size;
        }

    }
}

