#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long LINF = 2e16;
const int INF = 2e9;
const int magic = 348;
const double eps = 1e-10;
const double pi = 3.14159265;
inline int getint() {
  char ch;
  int res;
  bool f;
  while (!isdigit(ch = getchar()) && ch != '-') {
  }
  if (ch == '-')
    f = false, res = 0;
  else
    f = true, res = ch - '0';
  while (isdigit(ch = getchar())) res = res * 10 + ch - '0';
  return f ? res : -res;
}
struct Ope {
  int first, second;
  bool type;
} ope[100048];
int tot = 0;
int pre[20048], rnk[20048];
int find_anc(int first) {
  while (pre[first] != first) first = pre[first];
  return first;
}
void update(int first, int second) {
  first = find_anc(first);
  second = find_anc(second);
  if (first == second) {
    ope[++tot] = Ope{first, second, false};
    return;
  }
  if (rnk[first] >= rnk[second]) {
    pre[second] = first;
    ope[++tot] = Ope{first, second, false};
    if (rnk[first] == rnk[second]) rnk[first]++, ope[tot].type = true;
  } else {
    ope[++tot] = Ope{second, first, false};
    pre[first] = second;
  }
}
void undo() {
  int first = ope[tot].first, second = ope[tot].second;
  pre[second] = second;
  if (ope[tot].type) rnk[first]--;
  tot--;
}
int n, e;
pair<int, int> edge[10048];
int ansnum;
vector<int> ans;
bool Conflict = false;
void Add(int first, int second) {
  update(first, second + n);
  update(first + n, second);
  if (find_anc(first) == find_anc(first + n) ||
      find_anc(second) == find_anc(second + n))
    Conflict = true;
}
void solve(int left, int right) {
  if (left == right) {
    ansnum++;
    ans.push_back(left);
    return;
  }
  int i, mid = (left + right) >> 1;
  Conflict = false;
  for (i = left; i <= mid; i++) Add(edge[i].first, edge[i].second);
  if (!Conflict) solve(mid + 1, right);
  for (i = left; i <= mid; i++) undo(), undo();
  Conflict = false;
  for (i = mid + 1; i <= right; i++) Add(edge[i].first, edge[i].second);
  if (!Conflict) solve(left, mid);
  for (i = mid + 1; i <= right; i++) undo(), undo();
  Conflict = false;
}
int main() {
  int i;
  n = getint();
  e = getint();
  if (e == 0) {
    printf("0\n");
    return 0;
  }
  for (i = 1; i <= e; i++) edge[i].first = getint(), edge[i].second = getint();
  for (i = 1; i <= n * 2; i++) pre[i] = i, rnk[i] = 1;
  solve(1, e);
  printf("%d\n", ansnum);
  if (ansnum) {
    sort(ans.begin(), ans.end());
    for (i = 0; i < int(ans.size()); i++) printf("%d ", ans[i]);
  }
  return 0;
}
