#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e4 + 100;
struct Date {
  int x, y;
  bool z;
};
stack<Date> S;
int n, m, x, y, flag;
struct dsu {
  int f[Maxn];
  bool odd[Maxn];
  void clear() {
    for (int i = 1; i <= n; i++) f[i] = i, odd[i] = false;
  }
  int find(int x, int w) {
    if (x == f[x]) return x;
    if (w) S.push((Date){x, f[x], odd[x]});
    int ans = find(f[x], w);
    odd[x] ^= odd[f[x]];
    return f[x] = ans;
  }
  bool merge(int x, int y, int w) {
    int u = find(x, w), v = find(y, w);
    if (u == v) return odd[x] == odd[y];
    if (w) S.push((Date){u, f[u], odd[u]});
    f[u] = y;
    odd[u] = odd[x] ^ 1;
    return false;
  }
  void restore() {
    while (!S.empty()) {
      Date i = S.top();
      f[i.x] = i.y;
      odd[i.x] = i.z;
      S.pop();
    }
  }
} Dsu;
struct Edge {
  int from, to;
};
vector<Edge> edges;
vector<int> ans;
int main() {
  scanf("%d %d", &n, &m);
  if (m == 0) {
    printf("0");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    edges.push_back((Edge){x, y});
  }
  int Len = sqrt(m + 0.5), N = (m - 1) / Len + 1;
  for (int i = 1; i <= N; i++) {
    Dsu.clear();
    flag = false;
    for (int j = 0; j < m; j++) {
      if (j < i * Len && j >= (i - 1) * Len) continue;
      int from = edges[j].from, to = edges[j].to;
      if (Dsu.merge(from, to, 0)) {
        flag = true;
        break;
      }
    }
    if (flag) continue;
    for (int j = (i - 1) * Len; j < min(i * Len, m); j++) {
      for (int k = (i - 1) * Len; k < min(i * Len, m); k++) {
        if (j == k) continue;
        if (Dsu.merge(edges[k].from, edges[k].to, 1)) {
          flag = true;
          break;
        }
      }
      if (!flag) ans.push_back(j + 1);
      Dsu.restore();
      flag = false;
    }
  }
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
}
