#include <bits/stdc++.h>
using namespace std;
const int lim = 10000;
set<int> adjl[lim + 1], digr[lim + 1], res, back, ans;
vector<int> lvl(lim + 1, 0), dpc(lim + 1, 0), dpnc(lim + 1, 0), pt(lim + 1, 0);
bool color[lim + 1];
map<pair<int, int>, int> idx;
void dfs(int u) {
  for (int v : adjl[u]) {
    if (lvl[v] == 0) {
      lvl[v] = lvl[u] + 1;
      color[v] = (!color[u]);
      pt[v] = u;
      digr[u].insert(v);
      dfs(v);
      dpc[u] += dpc[v];
      dpnc[u] += dpnc[v];
    } else if (lvl[v] < lvl[u]) {
      if (color[v] == color[u])
        dpc[u]++;
      else
        dpnc[u]++;
      if (digr[v].find(u) == digr[v].end()) {
        digr[u].insert(v);
        if (color[u] == color[v]) back.insert(idx[make_pair(u, v)]);
      }
    } else if (lvl[v] > lvl[u]) {
      if (color[v] == color[u])
        dpc[u]--;
      else
        dpnc[u]--;
    }
  }
  if (lvl[u] > 1) dpnc[u]--;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    adjl[a].insert(b);
    adjl[b].insert(a);
    idx[make_pair(a, b)] = i;
    idx[make_pair(b, a)] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (lvl[i] == 0) {
      lvl[i] = 1;
      color[i] = true;
      dfs(i);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (lvl[i] > 1) {
      if (dpc[i] == back.size() && dpnc[i] == 0) {
        res.insert(idx[make_pair(i, pt[i])]);
      }
    }
  }
  if (back.empty()) {
    cout << m << "\n";
    for (int i = 1; i <= m; i++) cout << i << " ";
  } else {
    if (back.size() == 1) {
      cout << res.size() + 1 << "\n";
      for (int x : res) ans.insert(x);
      for (int x : back) ans.insert(x);
      for (int x : ans) cout << x << " ";
    } else {
      cout << res.size() << "\n";
      for (int x : res) cout << x << " ";
    }
  }
}
