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 N = 200200;
long long n, m;
int a[N], b[N];
vector<int> g[N];
inline int get(int v, int id) { return a[id] ^ b[id] ^ v; }
int timer = 0;
int used[N], tin[N];
int d[N], par[N];
inline int upper(int a, int b) { return tin[a] <= tin[b]; }
inline void upd(int v, int add) { d[v] += add; }
int parid[N];
int fup[N];
inline void dfs(int v, int p = 0) {
  used[v] = 1;
  par[v] = p;
  tin[v] = ++timer;
  for (int id : g[v]) {
    int to = get(v, id);
    if (to == p) continue;
    if (!used[to]) {
      parid[to] = id;
      dfs(to, v);
    } else {
      if (!upper(to, v)) continue;
      int x = tin[to];
      upd(par[to], -1);
      upd(v, 1);
    }
  }
}
inline void calc(int v, int p = 0) {
  used[v] = 1;
  for (int id : g[v]) {
    int to = get(v, id);
    if (to == p) continue;
    if (!used[to]) {
      calc(to, v);
      d[v] += d[to];
    }
  }
}
vector<int> res;
inline void solve(int v, int p = 0) {
  used[v] = 1;
  if (d[v] != 1)
    fup[v] = v;
  else
    fup[v] = fup[p];
  for (int id : g[v]) {
    int to = get(v, id);
    if (to == p) continue;
    if (!used[to]) {
      solve(to, v);
    } else {
      if (!upper(to, v)) continue;
      if (upper(fup[v], par[to])) {
        int x = v;
        while (x != to) {
          res.push_back(parid[x]);
          x = par[x];
        }
        res.push_back(id);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> a[i] >> b[i];
    g[a[i]].push_back(i);
    g[b[i]].push_back(i);
  }
  vector<int> roots;
  for (int i = 1; i <= n; ++i)
    if (!used[i]) {
      roots.push_back(i);
      dfs(i);
    }
  memset(used, 0, sizeof used);
  for (int x : roots) calc(x);
  memset(used, 0, sizeof used);
  for (int x : roots) solve(x);
  sort(res.begin(), res.end());
  cout << res.size() << '\n';
  for (int x : res) cout << x << ' ';
  return 0;
}
