#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, m, dep[maxn], col[maxn], par[maxn], cntbad, bad[maxn], good[maxn];
vector<pair<int, int> > G[maxn], tG[maxn], oG[maxn];
vector<pair<int, pair<int, int> > > E;
vector<int> ans;
bool vis[maxn];
void initGo(int x, int p, int d, int c) {
  par[x] = p;
  dep[x] = d;
  col[x] = c;
  vis[x] = true;
  for (int i = 0; i < G[x].size(); i++)
    if (G[x][i].first != p)
      if (!vis[G[x][i].first]) {
        int y = G[x][i].first, ord = G[x][i].second;
        tG[x].push_back(make_pair(y, ord));
        tG[y].push_back(make_pair(x, ord));
        initGo(y, x, d + 1, 1 - c);
      }
}
void Dfs(int x) {
  vis[x] = true;
  for (int i = 0; i < tG[x].size(); i++) {
    int y = tG[x][i].first, ord = tG[x][i].second;
    if (y != par[x]) {
      Dfs(y);
      bad[x] += bad[y];
      good[x] += good[y];
    }
  }
  for (int i = 0; i < G[x].size(); i++)
    if (G[x][i].first != par[x] && par[G[x][i].first] != x) {
      int y = G[x][i].first, z = (dep[x] < dep[y]) ? (-1) : 1;
      if (col[y] == col[x])
        bad[x] += z, cntbad++;
      else
        good[x] += z;
    }
}
void Dfs2(int x) {
  vis[x] = true;
  for (int i = 0; i < tG[x].size(); i++)
    if (tG[x][i].first != par[x]) {
      int y = tG[x][i].first, ord = tG[x][i].second;
      if (good[y] == 0 && bad[y] == cntbad) ans.push_back(ord + 1);
      Dfs2(y);
    }
}
int main() {
  scanf("%d%d", &n, &m);
  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));
    E.push_back(make_pair(i, make_pair(x, y)));
  }
  for (int i = 0; i < n; i++)
    if (!vis[i]) initGo(i, -1, 0, 0);
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++)
    if (!vis[i]) Dfs(i);
  cntbad /= 2;
  if (cntbad == 0) {
    printf("%d\n", m);
    for (int i = 0; i < m; i++) printf("%d ", i + 1);
    return 0;
  }
  if (cntbad == 1) {
    for (int i = 0; i < E.size(); i++) {
      int x = E[i].second.first, y = E[i].second.second, z = E[i].first;
      if (col[x] == col[y]) {
        ans.push_back(i + 1);
        break;
      }
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 0; i < n; i++)
    if (!vis[i]) Dfs2(i);
  sort(ans.begin(), ans.end());
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  return 0;
}
