#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
int color[10005];
int d[10005];
int par[10005];
pair<int, int> err[10005];
int cnt_err = 0;
int err_ed;
void dfs(int v, int p, int df, int c) {
  color[v] = c;
  par[v] = p;
  d[v] = df;
  int ok = 0;
  int bad = 0;
  for (int i = 0; i < g[v].size(); i++) {
    pair<int, int> pp = g[v][i];
    int tmp = pp.first;
    int ppar = pp.second;
    if ((d[tmp] + 1 == d[v]) && (d[tmp] != -1)) continue;
    if (color[tmp] == -1) {
      dfs(tmp, ppar, df + 1, 1 - c);
      ok += err[tmp].first;
      bad += err[tmp].second;
    } else {
      if (d[tmp] > d[v]) {
        if (color[tmp] == color[v])
          bad--;
        else
          ok--;
      } else {
        if (color[tmp] == color[v]) {
          bad++;
          cnt_err++;
          err_ed = ppar;
        } else
          ok++;
      }
    }
  }
  err[v] = make_pair(ok, bad);
}
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  g.resize(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    g[x].push_back(make_pair(y, i));
    g[y].push_back(make_pair(x, i));
  }
  memset(color, -1, sizeof(color));
  memset(d, -1, sizeof(d));
  for (int i = 0; i < n; i++)
    if (color[i] == -1) dfs(i, -1, 0, 0);
  if (!cnt_err) {
    printf("%d\n", m);
    for (int i = 0; i < m; i++) printf("%d%c", i + 1, i == n - 1 ? '\n' : ' ');
  } else {
    vector<int> ans;
    if (cnt_err == 1) ans.push_back(err_ed);
    for (int i = 0; i < n; i++) {
      if (par[i] != -1) {
        if (!err[i].first && (err[i].second == cnt_err)) ans.push_back(par[i]);
      }
    }
    sort(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for (int i = 0; i < ans.size(); i++)
      printf("%d%c", ans[i] + 1, i == ans.size() - 1 ? '\n' : ' ');
  }
  return 0;
}
