#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using adj_list = vector<vector<pair<int, int>>>;
adj_list g;
int bad_e;
vector<int> parent;
vector<int> depth;
void dfs1(int u) {
  for (auto [v, id] : g[u]) {
    if (parent[v] == -1) {
      parent[v] = u;
      depth[v] = depth[u] + 1;
      dfs1(v);
    } else if (parent[u] != v) {
      if (depth[u] > depth[v]) continue;
      if ((depth[u] ^ depth[v]) & 1) continue;
      ++bad_e;
    }
  }
}
vector<int> dp1;
vector<int> dp2;
void dfs2(int u) {
  for (auto [v, id] : g[u]) {
    if (parent[v] == u) {
      dfs2(v);
      dp1[u] += dp1[v];
      dp2[u] += dp2[v];
    } else if (parent[u] != v) {
      if (depth[u] > depth[v]) {
        ++dp1[u];
        if (!((depth[u] ^ depth[v]) & 1)) ++dp2[u];
      } else {
        --dp1[u];
        if (!((depth[u] ^ depth[v]) & 1)) --dp2[u];
      }
    }
  }
}
vector<int> ans;
void dfs3(int u) {
  for (auto [v, id] : g[u]) {
    if (parent[v] == u) {
      dfs3(v);
    } else if (parent[u] == v) {
      if (dp1[u] == bad_e && dp2[u] == bad_e) ans.push_back(id);
    } else if (parent[u] != v && depth[u] > depth[v]) {
      if (bad_e == 1 && !((depth[u] ^ depth[v]) & 1)) ans.push_back(id);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  g = adj_list(n);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }
  parent = vector<int>(n, -1);
  depth = vector<int>(n);
  dp1 = vector<int>(n, 0);
  dp2 = vector<int>(n, 0);
  int bad_comps = 0;
  for (int u = 0; u < n; ++u) {
    if (parent[u] != -1) continue;
    parent[u] = u;
    depth[u] = 0;
    bad_e = 0;
    dfs1(u);
    if (bad_e == 0) continue;
    ++bad_comps;
    dfs2(u);
    dfs3(u);
  }
  if (bad_comps == 0) {
    cout << m << '\n';
    for (int i = 1; i <= m; ++i) {
      cout << i << ' ';
    }
    cout << '\n';
  } else if (bad_comps == 1) {
    sort(ans.begin(), ans.end());
    cout << ans.size() << '\n';
    for (int i : ans) {
      cout << i << ' ';
    }
    cout << '\n';
  } else {
    cout << 0 << '\n';
  }
  return 0;
}
