#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> son[N], root, pe, ans;
vector<pair<int, int>> e[N];
pair<int, int> E[N], par[N];
int cnt[N], cnt2[N], dfn[N];
int n, m, u, v, dt;
void dfs(int u) {
  dfn[u] = ++dt;
  for (auto p : e[u]) {
    int v = p.first, id = p.second;
    if (!dfn[v]) {
      dfs(v);
      son[u].push_back(v);
      par[v] = make_pair(u, id);
    } else if (dfn[u] < dfn[v]) {
      cnt[u]--;
      cnt[v]++;
      pe.push_back(id);
    }
  }
}
void dfs2(int u) {
  for (auto v : son[u]) {
    dfs2(v);
    cnt[u] += cnt[v];
  }
  cnt2[u] = cnt[u] >= 2;
}
void dfs3(int u) {
  for (auto v : son[u]) {
    cnt2[v] += cnt2[u];
    dfs3(v);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &u, &v);
    E[i] = make_pair(u, v);
    e[u].push_back(make_pair(v, i));
    e[v].push_back(make_pair(u, i));
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) {
      dfs(i);
      root.push_back(i);
    }
  for (int u : root) dfs2(u);
  for (int u : root) dfs3(u);
  for (int p : pe) {
    int u = E[p].first, v = E[p].second;
    if (dfn[v] < dfn[u]) swap(u, v);
    if (cnt2[u] == cnt2[v]) {
      ans.push_back(p);
      while (v != u) {
        ans.push_back(par[v].second);
        v = par[v].first;
      }
    }
  }
  sort(ans.begin(), ans.end());
  printf("%d\n", (int)ans.size());
  for (int p : ans) printf("%d ", p);
  return 0;
}
