#include <bits/stdc++.h>
using namespace std;
int n, m, ans, col[1000005], flag[1000005], tot, res[1000005];
int k = 1, la[1000005], ff[1000005 * 2], check[1000005], pre[1000005], pos,
    del[1000005];
int cnt, f[1000005], g[1000005];
struct node {
  int a, b;
} e[1000005 * 2];
map<pair<int, int>, int> MAP;
void add(int a, int b) {
  e[++k] = (node){a, b};
  ff[k] = la[a];
  la[a] = k;
  e[++k] = (node){b, a};
  ff[k] = la[b];
  la[b] = k;
}
void dfs(int x, int fa) {
  check[x] = flag[x] = 1;
  col[x] = -col[fa];
  for (int a = la[x]; a; a = ff[a]) {
    if (e[a].b == fa) continue;
    if (!check[e[a].b]) {
      pre[e[a].b] = a;
      dfs(e[a].b, x);
      f[x] += f[e[a].b];
      g[x] += g[e[a].b];
      continue;
    }
    if (col[e[a].b] == col[x]) {
      if (flag[e[a].b]) {
        if (!cnt) pos = a;
        cnt++;
        f[x]++;
      } else
        f[x]--;
    } else {
      if (flag[e[a].b])
        g[x]++;
      else
        g[x]--;
    }
  }
  flag[x] = 0;
}
int main() {
  int a, b;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b), add(a, b);
    int num = MAP[make_pair(a, b)];
    if (num) del[i] = 1, del[num] = 1;
    MAP[make_pair(a, b)] = i;
  }
  col[0] = 1;
  for (int i = 1; i <= n; i++)
    if (!check[i]) dfs(i, 0);
  if (!cnt)
    for (int i = 1; i <= m; i++) res[++tot] = i;
  else {
    if (cnt == 1 && !del[pos >> 1]) res[++tot] = (pos >> 1);
    for (int i = 1; i <= n; i++) {
      if (f[i] == cnt && !g[i] && !del[pre[i] >> 1])
        if (!pre[i]) {
          for (int a = la[i]; a; a = ff[a])
            if (e[a].b == i && !del[a >> 1]) res[++tot] = (a >> 1);
        } else
          res[++tot] = (pre[i] >> 1);
    }
  }
  sort(res + 1, res + tot + 1);
  tot = unique(res + 1, res + tot + 1) - res - 1;
  printf("%d\n", tot);
  for (int i = 1; i < tot; i++) printf("%d ", res[i]);
  if (tot) printf("%d\n", res[tot]);
  return 0;
}
