#include <bits/stdc++.h>
using namespace std;
struct node {
  int to, id;
};
vector<node> E[10005];
vector<int> Ans;
int dep[10005], fa[10005][15], Id[10005], S1[10005], S0[10005], Stk[10005], cnt,
    n1, n, m;
bool mk[10005], Mk[10005];
void dfs(int x, int f) {
  mk[x] = 1;
  dep[x] = dep[f] + 1, fa[x][0] = f;
  for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) {
    int y = E[x][i].to;
    if (!mk[y]) {
      Stk[++cnt] = y;
      Id[y] = E[x][i].id;
      dfs(y, x);
    }
  }
}
int LCA(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  int d = dep[y] - dep[x];
  for (int i = (0), i_ = (13); i <= i_; i++)
    if (d & (1 << i)) y = fa[y][i];
  for (int i = (13), i_ = (0); i >= i_; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return x == y ? x : fa[x][0];
}
void Init() {
  for (int j = (1), j_ = (13); j <= j_; j++)
    for (int i = (1), i_ = (cnt); i <= i_; i++)
      fa[Stk[i]][j] = fa[fa[Stk[i]][j - 1]][j - 1];
}
void Dfs(int x) {
  for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) {
    int y = E[x][i].to;
    if (Id[y] == E[x][i].id)
      Dfs(y);
    else if (dep[y] < dep[x] && y != fa[x][0]) {
      if ((dep[x] & 1) == (dep[y] & 1)) {
        n1++;
        S1[x]++, S1[y]++, S1[LCA(x, y)] -= 2;
        Mk[E[x][i].id] = 1;
      } else
        S0[x]++, S0[y]++, S0[LCA(x, y)] -= 2;
    }
  }
}
void DFS(int x) {
  for (int i = (0), i_ = (E[x].size() - 1); i <= i_; i++) {
    int y = E[x][i].to;
    if (Id[y] == E[x][i].id) {
      DFS(y);
      S0[x] += S0[y], S1[x] += S1[y];
    }
  }
}
void Deal() {
  if (!n1) {
    for (int i = (1), i_ = (m); i <= i_; i++) Ans.push_back(i);
    return;
  }
  for (int i = (1), i_ = (n); i <= i_; i++)
    if (S1[i] == n1 && !S0[i]) Ans.push_back(Id[i]);
  if (n1 == 1)
    for (int i = (1), i_ = (m); i <= i_; i++)
      if (Mk[i]) Ans.push_back(i);
}
int main() {
  int a, b;
  scanf("%d%d", &n, &m);
  for (int i = (1), i_ = (m); i <= i_; i++) {
    scanf("%d%d", &a, &b);
    E[a].push_back((node){b, i});
    E[b].push_back((node){a, i});
  }
  for (int i = (1), i_ = (n); i <= i_; i++)
    if (!mk[i]) cnt = 0, dfs(i, 0), Init(), Dfs(i), DFS(i);
  Deal();
  printf("%d\n", Ans.size());
  sort(Ans.begin(), Ans.end());
  for (int i = (0), i_ = (Ans.size() - 1); i <= i_; i++) printf("%d ", Ans[i]);
  puts("");
  return 0;
}
