#include <bits/stdc++.h>
using namespace std;
void setIO(string s) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn = 1e4 + 5;
int n, m, dp[mxn][2], lvl[mxn], cor[mxn], cnt = 0;
vector<int> g[mxn];
map<pair<int, int>, int> mp;
vector<int> ans;
void dfs(int i) {
  dp[i][0] = dp[i][1] = 0;
  for (int j : g[i]) {
    if (!lvl[j]) {
      lvl[j] = lvl[i] + 1;
      cor[j] = cor[i] ^ 1;
      dfs(j);
      dp[i][0] += dp[j][0];
      dp[i][1] += dp[j][1];
    } else if (lvl[j] < lvl[i]) {
      if (cor[j] == cor[i]) {
        dp[i][1]++;
        cnt++;
      } else
        dp[i][0]++;
    } else if (lvl[j] > lvl[i]) {
      if (cor[j] == cor[i])
        dp[i][1]--;
      else
        dp[i][0]--;
    }
  }
  dp[i][0]--;
}
bool visto[mxn];
void dfs1(int i) {
  visto[i] = true;
  for (int j : g[i]) {
    if (lvl[j] == lvl[i] + 1) {
      if (dp[j][1] == cnt && !dp[j][0]) ans.push_back(mp[{i, j}]);
      dfs1(j);
    } else if (lvl[j] + 1 != lvl[i] && lvl[j] < lvl[i]) {
      if (cor[j] == cor[i] && cnt == 1) ans.push_back(mp[{i, j}]);
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
    mp[{x, y}] = i + 1;
    mp[{y, x}] = i + 1;
  }
  for (int i = 1; i <= n; i++) {
    if (lvl[i]) continue;
    lvl[i] = 1;
    dfs(i);
    dp[i][0]++;
  }
  if (!cnt) {
    cout << m << "\n";
    for (int i = 1; i <= m; i++) cout << i << " ";
    cout << "\n";
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (!visto[i]) dfs1(i);
  cout << int(ans.size()) << "\n";
  sort(ans.begin(), ans.end());
  for (int i : ans) cout << i << " ";
  cout << "\n";
  return 0;
}
