#include <bits/stdc++.h>
using namespace std;
int N, M, t, l, r, pt, len, rlen;
int mark[20010], fa[20010], step[20010], num[20010], root[20010];
int st[20010], ne[20010], go[20010], x[20010], y[20010];
;
int A[20010], B[20010], q[20010], dpa[20010], dpb[20010], ans[20010];
bool b[20010];
void dfs(int x) {
  b[x] = true;
  for (int i = st[x]; i; i = ne[i])
    if (go[i] != fa[x]) {
      if (!b[go[i]]) {
        mark[(i + 1) / 2] = 1;
        fa[go[i]] = x;
        num[go[i]] = (i + 1) / 2;
        step[go[i]] = step[x] + 1;
        dfs(go[i]);
      } else {
        if (((step[x] + step[go[i]]) & 1) == 0)
          mark[(i + 1) / 2] = 2;
        else
          mark[(i + 1) / 2] = 3;
      }
    }
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++) {
    scanf("%d%d", &x[i], &y[i]);
    ne[++pt] = st[x[i]];
    st[x[i]] = pt;
    go[pt] = y[i];
    ne[++pt] = st[y[i]];
    st[y[i]] = pt;
    go[pt] = x[i];
  }
  for (int i = 1; i <= N; i++)
    if (step[i] == 0) {
      dfs(i);
      root[++rlen] = i;
    }
  t = 0;
  for (int i = 1; i <= M; i++) {
    if (step[x[i]] > step[y[i]]) swap(x[i], y[i]);
    if (mark[i] == 2) {
      A[x[i]]--;
      A[y[i]]++;
      t++;
    } else if (mark[i] == 3) {
      B[x[i]]--;
      B[y[i]]++;
    }
  }
  if (t == 0) {
    printf("%d\n", M);
    for (int i = 1; i <= M; i++) printf("%d ", i);
    return 0;
  }
  if (t == 1) {
    for (int i = 1; i <= M; i++)
      if (mark[i] == 2) ans[++len] = i;
  }
  l = 1;
  for (int i = 1; i <= rlen; i++) q[++r] = root[i];
  for (; l <= r; l++) {
    int x = q[l];
    for (int i = st[x]; i; i = ne[i])
      if (mark[(i + 1) / 2] == 1)
        if (step[go[i]] > step[x]) q[++r] = go[i];
  }
  for (int i = r; i; i--) {
    int x = q[i];
    dpa[x] += A[x];
    dpb[x] += B[x];
    if (dpb[x] == 0) {
      if (dpa[x] == t) ans[++len] = num[x];
    }
    dpa[fa[x]] += dpa[x];
    dpb[fa[x]] += dpb[x];
  }
  printf("%d\n", len);
  sort(ans + 1, ans + len + 1);
  for (int i = 1; i <= len; i++) printf("%d ", ans[i]);
}
