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 

#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, e, f, g, n, m, k, l, ans1;
long long fix[500005], don[500005], P[25][500005], ans[500005], B[500005],
    A[500005], edge[500005];
map<pair<long long, long long>, long long> idx;
vector<long long> v[500005];
long long get_col(long long x) {
  if (B[x] == x) return x;
  B[x] = get_col(B[x]);
  return B[x];
}
void col(long long x, long long y) { B[get_col(x)] = get_col(y); }
void gaferadeba(long long x, long long y) {
  edge[get_col(y)] = idx[{x, P[0][y]}];
  x = get_col(x);
  y = get_col(y);
  while (x != y) {
    col(x, y);
    A[y] += A[x];
    x = get_col(P[0][x]);
  }
  A[y]++;
}
long long aweva(long long x, long long simagle) {
  for (long long i = 20; i >= 0; i--) {
    if ((1 << i) > simagle) continue;
    simagle -= (1 << i);
    x = P[i][x];
  }
  return x;
}
void dfs(long long x, long long y) {
  fix[x] = 1;
  don[x] = don[y] + 1;
  P[0][x] = y;
  for (long long i = 1; i <= 20; i++) {
    P[i][x] = P[i - 1][P[i - 1][x]];
  }
  for (long long i = 0; i < v[x].size(); i++) {
    if (v[x][i] == y) continue;
    if (fix[v[x][i]] == 0) dfs(v[x][i], x);
  }
}
void dfs1(long long x, long long y) {
  fix[x] = 1;
  for (long long i = 0; i < v[x].size(); i++) {
    if (v[x][i] == y) continue;
    if (fix[v[x][i]] == 0)
      dfs1(v[x][i], x);
    else {
      if (don[x] > don[v[x][i]]) {
        gaferadeba(x, aweva(x, don[x] - don[v[x][i]] - 1));
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) B[i] = i;
  for (long long i = 1; i <= m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
    idx[{a, b}] = i;
    idx[{b, a}] = i;
  }
  for (long long i = 1; i <= n; i++)
    if (fix[i] == 0) dfs(i, 0);
  for (long long i = 1; i <= n; i++) fix[i] = 0;
  for (long long i = 1; i <= n; i++)
    if (fix[i] == 0) dfs1(i, 0);
  for (long long i = 1; i <= n; i++) {
    a = get_col(i);
    if (A[a] == 1) {
      ans[idx[{i, P[0][i]}]] = 1;
      ans[edge[a]] = 1;
    }
  }
  for (long long i = 1; i <= m; i++)
    if (ans[i] == 1) ans1++;
  cout << ans1 << endl;
  for (long long i = 1; i <= m; i++)
    if (ans[i] == 1) cout << i << " ";
}
