#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
int n, m;
struct edge {
  int to, nxt, id;
} e[300005 << 1];
int tot, head[300005];
inline void adde(int u, int v, int id) {
  e[++tot] = (edge){v, head[u], id};
  head[u] = tot;
}
int dep[300005], fa[300005], top[300005];
int size[300005], son[300005], num[300005];
void dfs1(int u, int pa) {
  size[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == pa) continue;
    dep[v] = dep[u] + 1, fa[v] = u, num[v] = e[i].id;
    dfs1(v, u);
    size[u] += size[v];
    if (size[v] > size[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int tp) {
  top[u] = tp;
  if (son[u]) dfs2(son[u], tp);
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa[u] || v == son[u]) continue;
    dfs2(v, v);
  }
}
inline int lca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    u = fa[top[u]];
  }
  if (dep[u] < dep[v]) swap(u, v);
  return v;
}
inline int getdis(int u, int v) { return dep[u] + dep[v] - 2 * dep[lca(u, v)]; }
int c[300005], cnt;
bool vis[300005];
void dfs(int u) {
  vis[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa[u]) continue;
    dfs(v);
    c[u] += c[v];
  }
}
int f[300005];
int getf(int x) { return x == f[x] ? x : f[x] = getf(f[x]); }
struct node {
  int u, v, id;
} a[300005];
int k;
vector<int> res;
signed main() {
  n = read(), m = read();
  for (register int i = (1); i <= (n); ++i) f[i] = i;
  for (register int i = (1); i <= (m); ++i) {
    int u = read(), v = read();
    if (getf(u) != getf(v)) {
      f[getf(u)] = getf(v);
      adde(u, v, i), adde(v, u, i);
    } else
      a[++k] = (node){u, v, i};
  }
  int eid = 0;
  for (register int i = (1); i <= (n); ++i)
    if (!dep[i]) dfs1(i, 0), dfs2(i, i);
  for (register int i = (1); i <= (k); ++i) {
    int u = a[i].u, v = a[i].v, d = getdis(u, v), val = 1;
    if (d & 1)
      val = -1;
    else
      cnt++, eid = a[i].id;
    c[u] += val, c[v] += val, c[lca(u, v)] -= 2 * val;
  }
  for (register int i = (1); i <= (n); ++i)
    if (!vis[i]) dfs(i);
  if (!cnt)
    for (register int i = (1); i <= (m); ++i) res.push_back(i);
  else
    for (register int i = (1); i <= (n); ++i)
      if (c[i] == cnt) res.push_back(num[i]);
  if (cnt == 1) res.push_back(eid);
  sort(res.begin(), res.end());
  cout << res.size() << endl;
  for (int i = 0; i < res.size(); ++i) cout << res[i] << ' ';
  return 0;
}
