#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a[100010 << 3];
int fa[100010], v[100010], o, p, n, m, i, siz[100010];
vector<int> ans, st;
pair<int, int> find(int x) {
  if (fa[x] == x) return make_pair(x, 0);
  pair<int, int> ret = find(fa[x]);
  ret.second ^= v[x];
  return ret;
}
int insert(int a, int b, int& top) {
  pair<int, int> a1 = find(a);
  pair<int, int> a2 = find(b);
  int f1 = a1.first, f2 = a2.first;
  if (f1 == f2) {
    if (a1.second == a2.second) return 0;
    return 1;
  }
  if (siz[f1] < siz[f2]) swap(f1, f2);
  fa[f2] = f1;
  siz[f1] += siz[f2];
  v[f2] = 1 ^ a1.second ^ a2.second;
  st.push_back(f2);
  top++;
  return 1;
}
void del(int x) {
  siz[fa[x]] -= siz[x];
  v[x] = 0;
  fa[x] = x;
}
void solve(int rt, int l, int r) {
  int top = 0;
  for (int i = 0; i < (int)a[rt].size(); i++) {
    if (insert(a[rt][i].first, a[rt][i].second, top) == 0) {
      while (top--) {
        del(st.back());
        st.pop_back();
      }
      return;
    }
  }
  if (l == r) {
    ans.push_back(l);
  } else {
    int mid = (l + r) / 2;
    solve((rt << 1), l, mid);
    solve((rt << 1 | 1), mid + 1, r);
  }
  while (top--) {
    del(st.back());
    st.pop_back();
  }
  return;
}
void add(int rt, int l, int r, int x, int y, pair<int, int> t) {
  if (x <= l && r <= y) {
    a[rt].push_back(t);
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid) add((rt << 1), l, mid, x, y, t);
  if (y >= mid + 1) add((rt << 1 | 1), mid + 1, r, x, y, t);
  return;
}
int main() {
  scanf("%d %d", &n, &m);
  if (m == 0) {
    printf("0\n");
    return 0;
  }
  for (i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &o, &p);
    if (i > 1) add(1, 1, m, 1, i - 1, make_pair(o, p));
    if (i < m) add(1, 1, m, i + 1, m, make_pair(o, p));
  }
  solve(1, 1, m);
  printf("%d\n", ans.size());
  for (i = 0; i < ans.size(); i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
