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;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005, M = 2200006;
int n, m;
vector<int> g[N];
vector<int> gi[N];
pair<int, int> b[M];
int c[N];
int fup[N], tin[N], ti;
set<int> s;
void dfs(int x, int p) {
  c[x] = 1;
  fup[x] = tin[x] = ++ti;
  for (int i = 0; i < g[x].size(); ++i) {
    int h = g[x][i];
    if (h == p) continue;
    if (c[h])
      fup[x] = min(fup[x], tin[h]);
    else {
      dfs(h, x);
      if (fup[h] > tin[x]) s.insert(gi[x][i]);
      fup[x] = min(fup[x], fup[h]);
    }
  }
}
int k;
void dfs1(int x) {
  c[x] = k;
  for (int i = 0; i < g[x].size(); ++i) {
    int h = g[x][i];
    if (s.find(gi[x][i]) != s.end()) continue;
    if (!c[h]) dfs1(h);
  }
}
int qg[N];
vector<int> qk[N];
void solv() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
    gi[x].push_back(i);
    gi[y].push_back(i);
    b[i] = make_pair(x, y);
  }
  for (int x = 1; x <= n; ++x) {
    if (!c[x]) {
      dfs(x, -1);
    }
  }
  memset(c, 0, sizeof c);
  for (int x = 1; x <= n; ++x) {
    if (!c[x]) {
      ++k;
      dfs1(x);
    }
  }
  for (int x = 1; x <= n; ++x) qg[c[x]]++;
  for (int i = 0; i < m; ++i) {
    int x = b[i].first;
    int y = b[i].second;
    if (c[x] == c[y]) {
      qk[c[x]].push_back(i + 1);
    }
  }
  vector<int> ans;
  for (int i = 1; i <= k; ++i) {
    if (qg[i] == ((int)(qk[i]).size())) {
      for (int j = 0; j < qk[i].size(); ++j) ans.push_back(qk[i][j]);
    }
  }
  sort((ans).begin(), (ans).end());
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); ++i) printf("%d ", ans[i]);
  printf("\n");
}
int main() {
  solv();
  return 0;
}
