#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e4 + 9;
int n, m, mark[MAX], h[MAX], c[MAX];
bool e[MAX], mark2[MAX];
vector<int> ans;
vector<pair<int, int> > g[MAX];
vector<pair<pair<int, int>, int> > edge, bad, good;
void dfs(int v) {
  for (auto u : g[v])
    if (!mark[u.first])
      e[u.second] = true, mark[u.first] = 3 - mark[v], h[u.first] = h[v] + 1,
      dfs(u.first);
}
void dfs2(int v) {
  mark2[v] = true;
  for (auto u : g[v])
    if (!mark2[u.first]) dfs2(u.first), c[v] += c[u.first];
}
int main() {
  cin >> n >> m;
  for (int i = 0, u, v; i < m; i++)
    cin >> u >> v, u--, v--, edge.push_back({{u, v}, i}),
        g[v].push_back({u, i}), g[u].push_back({v, i});
  for (int i = 0; i < n; i++)
    if (!mark[i]) mark[i] = 1, dfs(i);
  for (auto i : edge)
    if (!e[i.second]) {
      if (mark[i.first.first] == mark[i.first.second])
        bad.push_back(i);
      else
        good.push_back(i);
    }
  if (bad.size() == 0)
    for (auto i : edge) ans.push_back(i.second);
  if (bad.size() == 1) ans.push_back(bad[0].second);
  for (auto i : bad) {
    if (h[i.first.first] > h[i.first.second])
      swap(i.first.first, i.first.second);
    c[i.first.first]--, c[i.first.second]++;
  }
  for (auto i : good) {
    if (h[i.first.first] > h[i.first.second])
      swap(i.first.first, i.first.second);
    c[i.first.first]++, c[i.first.second]--;
  }
  for (int i = 0; i < n; i++)
    if (!mark2[i]) dfs2(i);
  for (auto i : edge)
    if (e[i.second]) {
      if (h[i.first.first] > h[i.first.second])
        swap(i.first.first, i.first.second);
      if (c[i.first.second] == bad.size()) ans.push_back(i.second);
    }
  sort(ans.begin(), ans.end());
  ans.resize(unique(ans.begin(), ans.end()) - ans.begin());
  cout << ans.size() << '\n';
  for (auto i : ans) cout << i + 1 << " ";
}
