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;
vector<vector<int>> g;
vector<vector<int>> vg, gv;
vector<int> st, tt;
int dfs(int id, int p, int t) {
  st.push_back(id);
  int v, e, r = tt[id] = t;
  for (int n : g[id])
    if (n != p) {
      if (~tt[n]) {
        r = min(v = tt[n], r);
        continue;
      }
      r = min(v = dfs(n, id, t + 1), r);
      if (v == tt[n] || v == tt[n] - 1) {
        int gr = gv.size();
        gv.push_back(vector<int>());
        do {
          e = st.back();
          st.pop_back();
          gv[gr].push_back(e);
          vg[e].push_back(gr);
        } while (e != n);
        e = id;
        gv[gr].push_back(e);
        vg[e].push_back(gr);
      }
    }
  return r;
}
void get2Components() {
  int N = g.size();
  vg = vector<vector<int>>(N);
  gv = vector<vector<int>>();
  tt = vector<int>(N, -1);
  for (int i = 0; i < N; ++i) {
    if (tt[i] == -1) {
      dfs(i, i, 0);
    }
  }
}
struct Edge {
  int f, t, id, group;
  bool operator<(const Edge &e) const { return id < e.id; }
};
int findSame(vector<int> &a, vector<int> &b) {
  int ai = 0, bi = 0;
  while (ai != a.size() && bi != b.size()) {
    if (a[ai] < b[bi]) {
      ai++;
    } else if (a[ai] > b[bi]) {
      bi++;
    } else {
      return a[ai];
    }
  }
  assert(false);
}
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  scanf("%d%d", &N, &M);
  g = vector<vector<int>>(N);
  vector<Edge> e;
  for (int i = (0); i < (int)(M); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
    e.push_back({a, b, i});
  }
  get2Components();
  vector<int> ge(gv.size());
  for (Edge &el : e) {
    int group = findSame(vg[el.f], vg[el.t]);
    ge[group]++;
    el.group = group;
  }
  vector<int> good(gv.size(), 0);
  for (int i = 0; i < gv.size(); ++i) {
    good[i] = ge[i] == gv[i].size();
  }
  vector<Edge> res;
  for (Edge &el : e) {
    if (good[el.group]) {
      res.push_back(el);
    }
  }
  printf("%d\n", (int)res.size());
  for (Edge n : res) {
    printf("%d ", n.id + 1);
  }
  printf("\n");
  return 0;
}
