#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int tmp, tp, a, b, u, v, n, m, to[500010], deep[500010], nxt[500010],
    hd[500010], fa[100010], tofa[500010], num = -1, cf[500010];
bool tree[500010], vis[100010], flag;
void add(int u, int v) {
  nxt[++num] = hd[u], to[num] = v, hd[u] = num;
  nxt[++num] = hd[v], to[num] = u, hd[v] = num;
}
void dfs1(int pos, int f, int dp) {
  fa[pos] = f;
  vis[pos] = 1;
  deep[pos] = dp;
  for (int i = hd[pos]; i != -1; i = nxt[i]) {
    if (!vis[to[i]]) {
      tofa[to[i]] = i, tree[i] = 1;
      dfs1(to[i], pos, dp + 1);
    }
  }
}
void dfs(int pos) {
  vis[pos] = 1;
  for (int i = hd[pos]; i != -1; i = nxt[i]) {
    if (tree[i]) dfs(to[i]), cf[pos] += cf[to[i]];
  }
}
int main() {
  memset(hd, -1, sizeof hd);
  memset(nxt, -1, sizeof nxt);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    add(a, b);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs1(i, 0, 1);
  for (int i = 0; i <= num; i += 2) {
    if (tree[i] || tree[i + 1])
      continue;
    else
      u = to[i], v = to[i + 1];
    if (deep[u] < deep[v]) swap(u, v);
    cf[u]++;
    cf[v]--;
  }
  memset(vis, 0, sizeof vis);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  for (int i = 0; i <= num; i += 2) {
    if (tree[i] || tree[i + 1])
      continue;
    else
      u = to[i], v = to[i + 1];
    if (deep[u] < deep[v]) swap(u, v);
    flag = 0;
    tmp = u;
    for (; fa[tmp] != v; tmp = fa[tmp]) {
      if (cf[tmp] != 1) {
        flag = 1;
        break;
      }
    }
    if (!flag && cf[tmp] == 1) {
      ans.push_back((i + 2) / 2);
      while (u != v) {
        ans.push_back((tofa[u] + 2) / 2);
        u = fa[u];
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
}
