#include <bits/stdc++.h>
using namespace std;
int n, m;
struct mzls {
  int from, to;
} e[100005];
vector<pair<int, int> > g[100005];
int dfn[100005], f[100005], dd[100005], ncnt, pt[100005];
int chs[100005], lnk[100005];
vector<int> t[100005], ans;
inline void dfs(int x, int fa) {
  dfn[x] = ++ncnt;
  pt[x] = fa;
  for (int i = 0; i < g[x].size(); i++) {
    pair<int, int> pr = g[x][i];
    if (pr.first == fa) continue;
    if (!dfn[pr.first]) {
      t[x].push_back(pr.first);
      chs[pr.second] = 1;
      lnk[pr.first] = pr.second;
      dfs(pr.first, x);
    } else {
      if (dfn[pr.first] > dfn[x]) continue;
      f[x]++, f[pr.first]--;
    }
  }
}
int im[100005];
inline void dfs2(int x) {
  for (int i = 0; i < t[x].size(); i++) {
    dfs2(t[x][i]);
    dd[x] += dd[t[x][i]];
  }
  dd[x] += f[x];
}
inline void dfs3(int x) {
  im[x] = im[pt[x]] + (dd[x] > 1);
  for (int i = 0; i < t[x].size(); i++) dfs3(t[x][i]);
}
inline void solve(int x) {
  if (dfn[e[x].from] < dfn[e[x].to]) swap(e[x].from, e[x].to);
  int kk = im[e[x].from] - im[e[x].to];
  if (kk == 0) {
    int pla = e[x].from;
    while (pla != e[x].to) {
      ans.push_back(lnk[pla]);
      pla = pt[pla];
    }
    ans.push_back(x);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &e[i].from, &e[i].to);
    g[e[i].from].push_back(make_pair(e[i].to, i));
    g[e[i].to].push_back(make_pair(e[i].from, i));
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) dfs(i, 0), dfs2(i), dfs3(i);
  for (int i = 1; i <= m; i++)
    if (!chs[i]) solve(i);
  sort(ans.begin(), ans.end());
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  return 0;
}
