#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  if (f) x = -x;
  return x;
}
int a[100005], fa[100005], fd[100005], dep[100005], n, m;
int ans[200005], sta[100005], top[100005], cnt = 0;
int head[100005], nxt[200005], v[200005], id[200005], tot = 0;
bool vis[100005], ins[100005];
vector<int> vec[100005];
inline int getf(int a) {
  while (top[a] ^ a) a = top[a] = top[top[a]];
  return a;
}
inline void add(int a, int b, int qwq) {
  tot++;
  nxt[tot] = head[a];
  head[a] = tot;
  v[tot] = b;
  id[tot] = qwq;
}
inline void cover(int id, int a, int b) {
  int tag = 1;
  for (int i = a; i != b; i = fa[i]) {
    if (sta[i] > 0 || sta[i] == -1) {
      tag = 0;
      break;
    }
  }
  if (tag == 1) {
    for (int i = a; i != b; i = fa[i]) {
      sta[i] = id;
      vec[id].push_back(i);
    }
    return;
  }
  int i = a;
  while (dep[i] > dep[b]) {
    if (sta[i] == 0) {
      sta[i] = -1;
      top[i] = fa[i];
      i = fa[i];
      continue;
    }
    if (sta[i] == -1) {
      i = getf(i);
      continue;
    }
    if (sta[i] > 0) {
      int p = sta[i], j;
      for (j = 0; j < vec[p].size(); j++) {
        sta[vec[p][j]] = -1;
        top[vec[p][j]] = fa[vec[p][j]];
      }
      vec[p].clear();
      i = fa[i];
    }
  }
}
void dfs(int pos, int f) {
  vis[pos] = ins[pos] = 1;
  for (int i = head[pos]; i; i = nxt[i]) {
    if (v[i] == f) continue;
    if (vis[v[i]] && ins[v[i]]) {
      cover(id[i], pos, v[i]);
      continue;
    }
    if (vis[v[i]]) continue;
    dep[v[i]] = dep[pos] + 1;
    fa[v[i]] = pos;
    fd[v[i]] = id[i];
    dfs(v[i], pos);
  }
  ins[pos] = 0;
}
int main() {
  int i, j, a, b;
  n = read();
  m = read();
  for (i = 1; i <= m; i++) {
    a = read();
    b = read();
    add(a, b, i);
    add(b, a, i);
  }
  for (i = 1; i <= n; i++) top[i] = i;
  for (i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i, 0);
  }
  for (i = 1; i <= n; i++) {
    if (sta[i] > 0) {
      ans[++cnt] = sta[i];
      ans[++cnt] = fd[i];
    }
  }
  sort(ans + 1, ans + cnt + 1);
  cnt = unique(ans + 1, ans + cnt + 1) - ans - 1;
  printf("%d\n", cnt);
  for (i = 1; i <= cnt; i++) {
    printf("%d ", ans[i]);
  }
  return 0;
}
