public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = new StringTokenizer("");
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(out)));

        int N = nextInt();
        int M = nextInt();


        parent = new int[N + 1];
        size = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            parent[i] = i;
            size[i] = 1;
        }

        boolean[] edge = new boolean[M + 1];
        Edge[] edges = new Edge[M + 1];
        for (int m = 1; m <= M; m++) {
            int u = nextInt();
            int v = nextInt();
            Edge e = new Edge(u, v);
            edges[m] = e;
        }

        int count = 0;
        boolean[] visited = new boolean[N + 1];


        for (int i = M; i > 0; i--) {
            if (!visited[edges[i].v] || !visited[edges[i].u]) {
                visited[edges[i].v] = true;
                visited[edges[i].u] = true;
                edge[i] = true;
                count++;
                union(edges[i].v, edges[i].u);
            } else if (!connected(edges[i].v, edges[i].u)) {
                edge[i] = true;
                count++;
                union(edges[i].v, edges[i].u);
            }
        }

        pw.println(edge.length - 1 - count);
        for (int e = 1; e < edge.length; e++) {
            if (!edge[e]) {
                pw.println(e);
            }
        }

        reader.close();
        pw.close();
    }