#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> ans;
bool flag = 1;
vector<pair<int, int> > e;
int cnt = -1;
vector<bool> lastFlag;
vector<vector<pair<pair<int, int>*, pair<int, int> > > > lastD;
pair<int, int> d[100005];
pair<int, int> root(int u) {
  if (u == d[u].first) return {u, 0};
  pair<int, int> ret = root(d[u].first);
  lastD[cnt].push_back({d + u, d[u]});
  d[u] = {ret.first, d[u].second ^ ret.second};
  return d[u];
}
void join(int u, int v) {
  pair<int, int> ru = root(u), rv = root(v);
  if (ru.first == rv.first) {
    if (ru.second == rv.second) flag = 0;
    return;
  }
  lastD[cnt].push_back({d + ru.first, d[ru.first]});
  if (ru.second == rv.second)
    d[ru.first] = {rv.first, 1};
  else
    d[ru.first] = {rv.first, 0};
}
void add(int l, int r) {
  cnt++;
  lastFlag.push_back(flag);
  lastD.push_back(vector<pair<pair<int, int>*, pair<int, int> > >(0));
  for (int i = l; i <= r; ++i) join(e[i].first, e[i].second);
}
void undo(int cnt) {
  flag = lastFlag[cnt];
  reverse(lastD[cnt].begin(), lastD[cnt].end());
  for (auto i : lastD[cnt]) *(i.first) = i.second;
}
void divide(int l, int r) {
  if (l == r) {
    if (flag) ans.push_back(l);
    return;
  }
  int mid = (l + r) / 2;
  add(l, mid);
  int cur = cnt;
  divide(mid + 1, r);
  undo(cur);
  add(mid + 1, r);
  cur = cnt;
  divide(l, mid);
  undo(cur);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  if (m == 0) {
    cout << 0;
    return 0;
  }
  e.push_back({0, 0});
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    e.push_back({u, v});
  }
  for (int i = 1; i <= n; ++i) d[i] = {i, 0};
  divide(1, m);
  sort(ans.begin(), ans.end());
  cout << ans.size() << '\n';
  for (auto i : ans) cout << i << ' ';
  return 0;
}
