#include <bits/stdc++.h>
using namespace std;
int good[10005], bad[10005], lvl[10005], c[10005], p[10005];
int cc[10005];
int not_bipartite;
bool bipartite;
vector<int> adj[10005];
int wrong;
void dfs(int u, int pp, int id) {
  p[u] = pp;
  cc[u] = id;
  for (int v : adj[u]) {
    if (v == pp) continue;
    if (lvl[v] == -1) {
      lvl[v] = lvl[u] + 1;
      c[v] = !c[u];
      dfs(v, u, id);
      good[u] += good[v];
      bad[u] += bad[v];
    } else {
      if (c[u] == c[v]) bipartite = false;
      if (lvl[v] < lvl[u]) {
        if (c[u] == c[v]) {
          bad[u]++;
          bad[v]--;
          wrong++;
        } else {
          good[u]++;
          good[v]--;
        }
      }
    }
  }
}
bool check(int u, int v) {
  if (lvl[v] < lvl[u]) swap(u, v);
  if (p[v] == u) {
    if (good[v] == 0 && bad[v] == wrong) return true;
  } else {
    if (c[u] == c[v] && wrong == 1) {
      return true;
    }
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, u, v;
  cin >> n >> m;
  vector<pair<int, int> > edges;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    edges.push_back(pair<int, int>(u, v));
  }
  not_bipartite = 0;
  wrong = 0;
  int start = -1;
  for (int i = 1; i <= n; i++) lvl[i] = -1;
  for (int i = 1; i <= n; i++) {
    if (lvl[i] == -1) {
      bipartite = true;
      lvl[i] = 0;
      c[i] = 0;
      dfs(i, 0, i);
      if (!bipartite) {
        start = i;
        not_bipartite++;
      }
    }
  }
  if (not_bipartite == 0) {
    cout << m << '\n';
    for (int i = 1; i < m + 1; i++) cout << i << " ";
    return 0;
  } else if (not_bipartite >= 2) {
    cout << 0 << '\n';
    return 0;
  }
  vector<int> ans;
  for (int i = 0; i < m; i++) {
    pair<int, int> e = edges[i];
    if (cc[e.first] == cc[start] && cc[e.second] == cc[start]) {
      if (check(e.first, e.second)) {
        ans.push_back(i + 1);
      }
    }
  }
  cout << ans.size() << '\n';
  for (int x : ans) {
    cout << x << " ";
  }
  cout << '\n';
  return 0;
}
