#include <bits/stdc++.h>
using namespace std;
vector<int> g[10500], p[10500];
int cnt, s[10500], sp, ans[10500], tn;
bool dis[10500], vis[10500], e[10500];
void pfs(int u) {
  vis[u] = 1;
  for (int i = 0, v; i < g[u].size(); i++)
    if (!vis[v = g[u][i]]) {
      dis[v] = dis[u] ^ 1;
      e[p[u][i]] = 1;
      pfs(v);
    } else if (!e[p[u][i]]) {
      e[p[u][i]] = 1;
      if (dis[u] == dis[v]) {
        cnt++;
        s[u]++;
        s[v]--;
        sp = p[u][i];
      } else {
        s[u]--;
        s[v]++;
      }
    }
}
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0, v; i < g[u].size(); i++)
    if (!vis[v = g[u][i]]) {
      dfs(v);
      if (s[v] == cnt) ans[++tn] = p[u][i];
      s[u] += s[v];
    }
}
int n, m;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    p[u].push_back(i);
    g[v].push_back(u);
    p[v].push_back(i);
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i]) pfs(i);
  if (!cnt) {
    printf("%d\n", m);
    for (int i = 1; i <= m; i++) printf("%d ", i);
    return 0;
  }
  for (int i = 1; i <= n; i++) vis[i] = 0;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  if (cnt == 1) ans[++tn] = sp;
  printf("%d\n", tn);
  sort(ans + 1, ans + tn + 1);
  for (int i = 1; i <= tn; i++) printf("%d ", ans[i]);
  return 0;
}
