#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int maxm = 200020;
int head[maxn], cnt;
void init(int n) {
  for (int i = 1; i <= n; i++) head[i] = -1;
  cnt = 0;
}
struct edge {
  int to, next;
} E[maxm];
void add(int u, int v) {
  E[cnt].to = v;
  E[cnt].next = head[u];
  head[u] = cnt++;
}
int dfn[maxn], low[maxn], s1[maxn], s2[maxn], ebl[maxm], bccnum[maxn], idx, tp1,
    tp2, block;
vector<int> bcc[maxn], ebcc[maxn];
void tarjan(int u, int pre) {
  low[u] = dfn[u] = ++idx;
  s1[++tp1] = u;
  for (int i = head[u]; ~i; i = E[i].next) {
    int v = E[i].to;
    if (v == pre) continue;
    if (!dfn[v]) {
      s2[++tp2] = i >> 1;
      tarjan(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] >= dfn[u]) {
        block++;
        int vv;
        do {
          vv = s2[tp2--];
          ebl[vv] = block;
          bccnum[block]++;
          ebcc[block].push_back(vv);
        } while (vv != (i >> 1));
        do {
          vv = s1[tp1--];
          bcc[block].push_back(vv);
        } while (vv != v);
        bcc[block].push_back(u);
      }
    } else if (dfn[v] < dfn[u]) {
      s2[++tp2] = i >> 1;
      low[u] = min(low[u], dfn[v]);
    }
  }
}
int ans[maxm];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  init(n);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v);
    add(v, u);
  }
  for (int i = 1; i <= n; i++) {
    if (!dfn[i]) tarjan(i, -1);
  }
  int v1 = 0;
  for (int i = 1; i <= block; i++) {
    if (bccnum[i] == (int)bcc[i].size()) {
      for (int j : ebcc[i]) {
        ans[++v1] = j + 1;
      }
    }
  }
  sort(ans + 1, ans + v1 + 1);
  printf("%d\n", v1);
  for (int i = 1; i <= v1; i++) printf("%d%c", ans[i], i == v1 ? '\n' : ' ');
  return 0;
}
