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;
const int MAXN = 100100;
int n, lvl[MAXN], m, backUp[MAXN], backDown[MAXN], back[MAXN], anc[MAXN],
    desc[MAXN], f[MAXN];
vector<int> G[MAXN], ans, toproc[MAXN];
map<pair<int, int>, int> mp;
bool vis[MAXN];
void dfs(int v, int p) {
  lvl[v] = p == -1 ? 0 : lvl[p] + 1;
  backDown[v] = backUp[v] = back[v] = 0;
  anc[v] = v;
  desc[v] = -1;
  f[v] = p;
  for (auto it = G[v].begin(); it != G[v].end(); ++it)
    if (*it != p) {
      if (lvl[*it] == -1) {
        dfs(*it, v);
        back[v] += back[*it];
        if (lvl[anc[*it]] < lvl[anc[v]]) {
          anc[v] = anc[*it];
          desc[v] = desc[*it];
        }
      } else if (lvl[*it] < lvl[v]) {
        backUp[v]++;
        if (lvl[*it] < lvl[anc[v]]) {
          anc[v] = *it;
          desc[v] = v;
        }
      } else {
        assert(lvl[*it] > lvl[v]);
        backDown[v]++;
      }
    }
  back[v] += backUp[v] - backDown[v];
}
int st[MAXN];
int operacion(int i, int j) {
  if (i == -1) return j;
  if (j == -1) return i;
  return back[st[i]] > back[st[j]] ? i : j;
}
const int neutro = -1;
struct RMQ {
  int sz;
  int t[4 * MAXN];
  int &operator[](int p) { return t[sz + p]; }
  void init(int n) {
    sz = 1 << (32 - __builtin_clz(n));
    for (int i = (0); i < (2 * sz); i++) t[i] = neutro;
  }
  void updall() {
    for (int i = sz - 1; i >= 0; i--) t[i] = operacion(t[2 * i], t[2 * i + 1]);
  }
  int get(int i, int j) {
    if (i >= j) return neutro;
    return get(i, j, 1, 0, sz);
  }
  int get(int i, int j, int n, int a, int b) {
    if (j <= a || i >= b) return neutro;
    if (i <= a && b <= j) return t[n];
    int c = (a + b) / 2;
    return operacion(get(i, j, 2 * n, a, c), get(i, j, 2 * n + 1, c, b));
  }
  void set(int p, int val) {
    for (p += sz; p > 0 && t[p] != val;) {
      t[p] = val;
      p /= 2;
      val = operacion(t[p * 2], t[p * 2 + 1]);
    }
  }
} rmq;
void dfs2(int v, int p, int last, int d) {
  vis[v] = true;
  if (desc[v] >= 0) toproc[desc[v]].push_back(v);
  st[d] = v;
  rmq.set(d, d);
  for (auto it = toproc[v].begin(); it != toproc[v].end(); ++it) {
    assert(f[*it] != -1);
    assert(desc[*it] == v);
    assert(anc[v] == anc[*it]);
    int pos = rmq.get(lvl[anc[v]] + 1, d + 1);
    if (pos < 0) continue;
    assert(back[st[pos]] > 0);
    if (back[st[pos]] == 1) {
      ans.push_back(mp[pair<int, int>(*it, f[*it])]);
    }
  }
  for (auto it = G[v].begin(); it != G[v].end(); ++it)
    if (*it != p) {
      if (!vis[*it]) {
        dfs2(*it, v, back[v] != 1 ? v : last, d + 1);
      } else if (lvl[*it] < lvl[v]) {
        int pos = rmq.get(lvl[*it] + 1, d + 1);
        if (pos >= 0 && back[st[pos]] == 1) {
          ans.push_back(mp[pair<int, int>(v, *it)]);
        }
      }
    }
}
int main() {
  ios::sync_with_stdio(0);
  while (cin >> n >> m) {
    memset(toproc, 0, sizeof(toproc));
    memset(G, 0, sizeof(G));
    ans.clear();
    memset(lvl, -1, sizeof(lvl));
    mp.clear();
    for (int i = (0); i < (m); i++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
      mp[pair<int, int>(a, b)] = i;
      mp[pair<int, int>(b, a)] = i;
    }
    for (int i = (0); i < (n); i++)
      if (lvl[i] == -1) dfs(i, -1);
    memset(vis, 0, sizeof(vis));
    rmq.init(n);
    for (int i = (0); i < (n); i++)
      if (!vis[i]) dfs2(i, -1, i, 0);
    sort(ans.begin(), ans.end());
    cout << ((int)ans.size()) << endl;
    for (int i = (0); i < (((int)ans.size())); i++) {
      cout << ans[i] + 1;
      if (i < ((int)ans.size()) - 1) cout << ' ';
    }
    cout << endl;
  }
  return 0;
}
