#include <bits/stdc++.h>
using namespace std;
int getint() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
int pre[312345];
int find(int x) {
  int res = x;
  while (pre[res] != res) res = pre[res];
  int t;
  while (pre[x] != res) {
    t = pre[x];
    pre[x] = res;
    x = t;
  }
  return res;
}
int xx[312345], yy[312345];
int treeEdge[312345];
int head[312345];
int tot = 0;
struct edge {
  int to, next, id;
} e[312345 << 1];
void insert(int x, int y, int id) {
  e[++tot].to = y;
  e[tot].next = head[x];
  e[tot].id = id;
  head[x] = tot;
  e[++tot].to = x;
  e[tot].next = head[y];
  e[tot].id = id;
  head[y] = tot;
  return;
}
int fa[312345], dep[312345], id[312345];
int f[312345], g[312345];
void dfs(int x) {
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (!dep[y]) {
      dep[y] = dep[x] + 1;
      treeEdge[e[i].id] = 1;
      id[y] = e[i].id;
      fa[y] = x;
      dfs(y);
    }
  }
}
void dfs2(int x) {
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (treeEdge[e[i].id] && y != fa[x]) {
      dfs2(y);
      f[x] += f[y];
      g[x] += g[y];
    }
  }
}
int n, m, oldm;
int main() {
  n = getint();
  oldm = m = getint();
  for (int i = 1; i <= n; i++) pre[i] = i;
  for (int i = 1; i <= m; i++) {
    xx[i] = getint();
    yy[i] = getint();
    int x = find(xx[i]);
    int y = find(yy[i]);
    pre[x] = y;
  }
  vector<int> tmp;
  for (int i = 1; i <= n; i++)
    if (pre[i] == i) tmp.push_back(i);
  for (int i = 1; i < tmp.size(); i++) {
    xx[++m] = tmp[i - 1];
    yy[m] = tmp[i];
  }
  for (int i = 1; i <= m; i++) insert(xx[i], yy[i], i);
  dep[1] = 1;
  dfs(1);
  int ji = 0, jiid;
  for (int i = 1; i <= m; i++) {
    if (dep[xx[i]] < dep[yy[i]]) swap(xx[i], yy[i]);
    int x = xx[i], y = yy[i];
    if (!treeEdge[i]) {
      if ((dep[x] - dep[y]) & 1) {
        g[x]++;
        g[y]--;
      } else {
        ++ji;
        f[x]++;
        f[y]--;
        jiid = i;
      }
    }
  }
  if (ji == 0) {
    printf("%d\n", oldm);
    for (int i = 1; i <= oldm; i++) printf("%d ", i);
    return 0;
  }
  dfs2(1);
  tmp.clear();
  for (int i = 1; i <= n; i++) {
    if (f[i] == ji && !g[i]) tmp.push_back(id[i]);
  }
  if (ji == 1) tmp.push_back(jiid);
  sort(tmp.begin(), tmp.end());
  printf("%d\n", tmp.size());
  for (int i = 0; i < tmp.size(); i++) printf("%d ", tmp[i]);
  return 0;
}
