#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, n2 = 1, m, par[20010], hei[20010];
vector<pair<int, int> > dat[40010];
vector<int> ans;
stack<pair<pair<int, int>, int> > oper;
void upd(int k, int lb, int ub, int tlb, int tub, pair<int, int> val) {
  if (ub < tlb || tub < lb) return;
  if (tlb <= lb && ub <= tub) {
    dat[k].push_back(val);
    return;
  }
  upd(k * 2 + 1, lb, (lb + ub) / 2, tlb, tub, val);
  upd(k * 2 + 2, (lb + ub) / 2 + 1, ub, tlb, tub, val);
}
int FIND(int pos) {
  if (par[pos] != pos) return FIND(par[pos]);
  return par[pos];
}
void UNION(int pos, int pos2) {
  int a = FIND(pos), b = FIND(pos2);
  if (hei[a] < hei[b]) swap(a, b);
  oper.push(make_pair(make_pair(a, b), hei[a]));
  par[b] = a;
  hei[a] = max(hei[a], hei[b] + 1);
}
void undo() {
  par[oper.top().first.second] = oper.top().first.second;
  hei[oper.top().first.first] = oper.top().second;
  oper.pop();
}
void solve(int k, int lb, int ub) {
  int cnt = 0;
  for (int i = 0; i < dat[k].size(); i++) {
    UNION(dat[k][i].first, dat[k][i].second + n);
    UNION(dat[k][i].first + n, dat[k][i].second);
    cnt += 2;
    if (FIND(dat[k][i].first) == FIND(dat[k][i].first + n) ||
        FIND(dat[k][i].second) == FIND(dat[k][i].second + n)) {
      while (cnt--) undo();
      return;
    }
  }
  if (lb == ub) {
    if (lb < m) ans.push_back(lb + 1);
  } else {
    solve(k * 2 + 1, lb, (lb + ub) / 2);
    solve(k * 2 + 2, (lb + ub) / 2 + 1, ub);
  }
  while (cnt--) undo();
}
int main() {
  cin >> n >> m;
  while (n2 < m) n2 *= 2;
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    upd(0, 0, n2 - 1, 0, i - 1, make_pair(x, y));
    upd(0, 0, n2 - 1, i + 1, m - 1, make_pair(x, y));
  }
  for (int i = 1; i <= n * 2; i++) {
    par[i] = i;
    hei[i] = 1;
  }
  solve(0, 0, n2 - 1);
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  cout << endl;
  return 0;
}
