#include <bits/stdc++.h>
using namespace std;
bool ind[100009];
int n, m, hd[100009], cnt, ans[100009], sa;
int dfn[100009], low[100009], sd, q[100009], sq, L[100009], sl;
struct Edge {
  int to, nxt, i;
} edge[100009 << 1];
int read();
void add(int u, int v, int i) {
  edge[++cnt] = (Edge){v, hd[u], i};
  hd[u] = cnt;
  edge[++cnt] = (Edge){u, hd[v], i};
  hd[v] = cnt;
}
void Tarjan(int u) {
  dfn[u] = low[u] = ++sd;
  q[++sq] = u;
  for (int i = hd[u], v; i; i = edge[i].nxt) {
    int NL = sl;
    if (!ind[edge[i].i]) {
      L[++sl] = edge[i].i;
      ind[edge[i].i] = true;
    }
    if (!dfn[v = edge[i].to]) {
      Tarjan(v);
      low[u] = (low[u]) < (low[v]) ? (low[u]) : (low[v]);
      if (low[v] == dfn[u]) {
        int sum = 1;
        while (q[sq + 1] != v) ++sum, --sq;
        if (sum != sl - NL)
          while (sl > NL) --sl;
        else
          while (sl > NL) ans[++sa] = L[sl--];
      }
    } else
      low[u] = (low[u]) < (dfn[v]) ? (low[u]) : (dfn[v]);
  }
}
int main() {
  n = read(), m = read();
  for (int i = 1, u, v; i <= m; ++i) u = read(), v = read(), add(u, v, i);
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) Tarjan(i);
  sort(ans + 1, ans + 1 + sa);
  printf("%d\n", sa);
  for (int i = 1; i <= sa; ++i) printf("%d ", ans[i]);
  puts("");
  return 0;
}
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c > '9' || c < '0') f = (c == '-') ? -1 : f, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
