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.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.ArrayDeque;
import java.io.InputStreamReader;
import java.util.ArrayList;
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) {
                MagicComponents.Edge e = new MagicComponents.Edge(in.nextInt() - 1, in.nextInt() - 1, i);
                mc.addEdge(e.u, e.v);
                indeg[e.u]++;
                indeg[e.v]++;
            }
            mc.run();
            int[] id = new int[n];
            int idx = 0;
            boolean[] valid = new boolean[m];
            int ans = 0;
            for (ArrayList<MagicComponents.Edge> bcc : mc.bccs) {
                ++idx;
                int nodes = 0;
                for (MagicComponents.Edge e : bcc) {
                    if (id[e.u] != idx) {
                        id[e.u] = idx;
                        ++nodes;
                    }
                    if (id[e.v] != idx) {
                        id[e.v] = idx;
                        ++nodes;
                    }
                }
                if (nodes != bcc.size()) continue;
                for (MagicComponents.Edge e : bcc) {
                    ++ans;
                    valid[e.id] = true;
                }
            }
            out.println(ans);
            for (int i = 0; i < m; ++i) if (valid[i]) out.print((i + 1) + " ");
            out.println();
        }

    }

    static class MagicComponents {
        int num;
        int n;
        int edges;
        int[] dfsNum;
        int[] low;
        int[] vis;
        public ArrayList<Integer> cuts;
        public ArrayList<MagicComponents.Edge> bridges;
        public ArrayList<MagicComponents.Edge>[] adj;
        public ArrayList<ArrayList<MagicComponents.Edge>> bccs;
        ArrayDeque<MagicComponents.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 MagicComponents.Edge(u, v, edges));
            adj[v].add(new MagicComponents.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 (MagicComponents.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<MagicComponents.Edge> list = new ArrayList<>();
            for (; ; ) {
                MagicComponents.Edge e = eStack.pop();
                list.add(e);
                if (e.u == u) break;
            }
            bccs.add(list);
        }

        public static 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;
            }

        }

    }

    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());
        }

    }
}

