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>
const int N = 200010;
template <typename T>
void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c & 15);
  x *= f;
}
struct stac_set {
  int l, a[N];
  bool v[N];
  inline void push(int x) {
    a[++l] = x;
    v[x] = true;
  }
  inline void pop() { v[a[l--]] = false; }
  inline int top() { return a[l]; }
  inline bool insta(int x) { return v[x]; }
} sta;
struct edge {
  int t, c;
};
std::vector<edge> v[N];
int dfn[N], low[N], tot, ans[N], tme;
inline void add(int s, int t, int c) { v[s].push_back(edge{t, c}); }
inline int min(int a, int b) {
  if (a < b) return a;
  return b;
}
void tarjan(int u) {
  sta.push(u);
  low[u] = dfn[u] = ++tme;
  for (register int i = 0; i < v[u].size(); i++) {
    if (dfn[v[u][i].t] == 0) {
      tarjan(v[u][i].t);
      if (low[v[u][i].t] >= dfn[u]) {
        int tmptot = tot, cv = 1, ce = 0;
        while (sta.top() != u) {
          int tmp = sta.top();
          sta.pop();
          cv++;
          for (register int j = 0; j < v[tmp].size(); j++) {
            if (sta.insta(v[tmp][j].t)) {
              ce++;
              ans[++tmptot] = v[tmp][j].c;
            }
          }
        }
        if (cv == ce) tot = tmptot;
      }
      low[u] = min(low[u], low[v[u][i].t]);
    } else if (sta.insta(v[u][i].t)) {
      low[u] = min(low[u], low[v[u][i].t]);
    }
  }
}
int main() {
  int n, m;
  read(n);
  read(m);
  for (register int i = 1; i <= m; i++) {
    int x, y;
    read(x);
    read(y);
    add(x, y, i);
    add(y, x, i);
  }
  for (register int i = 1; i <= n; i++)
    if (dfn[i] == 0) tarjan(i);
  std::sort(ans + 1, ans + tot + 1);
  printf("%d\n", tot);
  if (tot > 0) {
    for (register int i = 1; i < tot; i++) printf("%d ", ans[i]);
    printf("%d\n", ans[tot]);
  }
}
