#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int from, to, nxt;
} e[50050];
int n, m, tot = 1, sum = 0, flag = 0;
int fir[20050];
int fa[20050] = {0};
int vis[20050] = {0};
int col[20050] = {0};
int f[20050] = {0}, g[20050] = {0};
int ans[20050];
void add(int from, int to) {
  e[++tot].nxt = fir[from];
  fir[from] = tot;
  e[tot].to = to;
  e[tot].from = from;
}
void ranse(int x, int num) {
  col[x] = num;
  vis[x] = 1;
  for (int i = fir[x]; i != -1; i = e[i].nxt) {
    if (fa[x] != (i ^ 1)) {
      int y = e[i].to;
      if (!vis[y]) {
        fa[y] = i;
        ranse(y, 1 - num);
        f[x] += f[y];
        g[x] += g[y];
      } else if (vis[y] == 1) {
        if (col[x] == col[y]) {
          sum++;
          flag = i;
          f[x]++;
        } else
          g[x]++;
      } else if (col[x] == col[y])
        f[x]--;
      else
        g[x]--;
    }
  }
  vis[x] = 2;
}
int main() {
  cin >> n >> m;
  memset(fir, -1, sizeof(fir));
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    add(a, b);
    add(b, a);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) ranse(i, 0);
  }
  int siz = 0;
  if (!sum) {
    for (int i = 1; i <= m; i++) ans[++siz] = i;
  } else {
    if (sum == 1) ans[++siz] = flag / 2;
    for (int i = 1; i <= n; i++) {
      if (f[i] == sum && !g[i]) ans[++siz] = fa[i] / 2;
    }
  }
  sort(ans + 1, ans + 1 + siz);
  printf("%d\n", siz);
  for (int i = 1; i <= siz; i++) printf("%d ", ans[i]);
  return 0;
}
