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 sys

#sys.setrecursionlimit(1000000)

class DisjointSet:
    def __init__(self, n):
        self.P = [-1] * n
    
    def SetOf(self, x: int):
        if self.P[x] < 0:
            return x
        self.P[x] = self.SetOf(self.P[x])
        return self.P[x] 
    
    def Merge(self, x: int, y: int):
        c_x = self.SetOf(x)
        c_y = self.SetOf(y)

        if c_x == c_y:
            return

        if abs(self.P[c_x]) < abs(self.P[c_y]):
            self.P[c_y] += self.P[c_x]
            self.P[c_x] = c_y
        else:
            self.P[c_x] += self.P[c_y]
            self.P[c_y] = c_x

class E:
    def __init__(self, u, v, ind):
        self.u = u
        self.v = v
        self.ind = ind

line = sys.stdin.readline().split()
N, M = int(line[0]), int(line[1])

g = [[] for _ in range(N)]
mp = dict()

for i in range(1, M + 1):
    line = sys.stdin.readline().split()
    u, v = int(line[0]) - 1, int(line[1]) -1
    mp[(u, v)] = mp[(v, u)] = i
    g[u].append((v, i))
    g[v].append((u, i))
    
dep = [0] * N
visited = [0] * N
pi = [-1] * N

edges = []

def dfs(c, p):
    visited[c] = -1
    pi[c] = p
    for tuple_I in g[c]:
        if p != tuple_I[0]:
            if pi[tuple_I[0]] == -1:
                dep[tuple_I[0]] = dep[c] + 1
                dfs(tuple_I[0], c)
            elif visited[tuple_I[0]] == -1:
                edges.append(E(c, tuple_I[0], tuple_I[1]))
    visited[c] = 1

for i in range(N):
    if not visited[i]:
        dfs(i, -1)

n = len(edges)
dsu = DisjointSet(n)
pp = pi.copy()
index = [-1] * N

for i in range(n):
    u, v, ind = edges[i].u, edges[i].v, edges[i].ind
    path = []
    while dep[u] > dep[v]:
        path.append(u)
        if index[u] == -1:
            index[u] = i
        else:
            dsu.Merge(i, index[u])
        u = pi[u]
    for x in range(len(path)):
        pi[x] = v

res = set()
for i in range(n):
    if dsu.P[i] == -1:
        res.add(edges[i].ind)
        u, v = edges[i].u, edges[i].v
        while u != v:
            res.add(mp[(u, pp[u])])
            u = pp[u]

tp = []
def puts(s):
    tp.append(s)

sys.stdout.write(str(len(res)) + '\n')
for i in res:
    puts(str(i))
puts("\n")
sys.stdout.write(" ".join(tp))
