#include <bits/stdc++.h>
char cc;
int C;
template <class T>
void read(T &x) {
  x = 0;
  C = 1;
  cc = getchar();
  while (!('0' <= cc && cc <= '9')) {
    if (cc == '-') C = -1;
    cc = getchar();
  }
  while (('0' <= cc && cc <= '9')) {
    x = x * 10 + cc - 48;
    cc = getchar();
  }
  x *= C;
}
using namespace std;
int fst[100010], to[100010 << 1], nxt[100010 << 1], etot;
int n, m;
void add_e(int x, int y) {
  static int &i = etot;
  to[i] = y;
  nxt[i] = fst[x];
  fst[x] = i++;
  to[i] = x;
  nxt[i] = fst[y];
  fst[y] = i++;
}
void init() {
  int a, b;
  read(n);
  read(m);
  memset(fst, -1, sizeof fst);
  for (int i = 1; i <= m; ++i) {
    read(a);
    read(b);
    add_e(a, b);
  }
}
bool vis[100010];
int col[100010], f[2][100010], cur[100010], p[100010], dep[100010], cnt[2],
    from[100010], ans, last[2];
int STA[100010], top;
void solve(int rt) {
  static int u, v, _;
  static bool flag;
  col[rt] = 0;
  dep[rt] = 0;
  cur[rt] = fst[rt];
  vis[STA[++top] = rt] = true;
  from[rt] = -1;
  while (top) {
    u = STA[top];
    flag = true;
    for (int i = cur[u]; ~i; i = nxt[i]) {
      v = to[i];
      if (~from[u] && v == to[from[u] ^ 1]) continue;
      if (p[u] == v) {
        p[u] = -1;
        f[0][u] += f[0][v];
        f[1][u] += f[1][v];
        continue;
      }
      if (vis[v]) {
        _ = col[v] ^ col[u] ^ 1;
        if (dep[v] < dep[u]) {
          ++f[_][u];
          ++cnt[_];
          last[_] = (i >> 1) + 1;
        } else
          --f[_][u];
        continue;
      } else {
        col[v] = col[u] ^ 1;
        cur[v] = fst[v];
        dep[v] = dep[u] + 1;
        vis[STA[++top] = v] = true;
        from[v] = i;
        cur[u] = i;
        p[u] = v;
        flag = false;
        break;
      }
    }
    if (flag) --top;
  }
}
int main() {
  init();
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) solve(i);
  if (cnt[1] == 0) {
    printf("%d\n", m);
    for (int i = 1; i <= m; ++i) printf("%d ", i);
  } else {
    vector<int> rec;
    if (cnt[1] == 1) {
      for (int i = 1; i <= n; ++i)
        if (f[0][i] == 0 && f[1][i]) rec.push_back((from[i] >> 1) + 1);
      rec.push_back(last[1]);
    } else
      for (int i = 1; i <= n; ++i)
        if (f[0][i] == 0 && f[1][i] == cnt[1])
          rec.push_back((from[i] >> 1) + 1);
    sort(rec.begin(), rec.end());
    printf("%d\n", rec.size());
    for (int i = 0; i <= (int)rec.size() - 1; ++i) printf("%d ", rec[i]);
  }
  return 0;
}
