#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5;
const int inf = 1 << 30;
bool viz[nmax + 1], f[nmax + 1];
int h[nmax + 1];
int d[nmax + 1];
int nrc;
int noduri[nmax + 1][2];
vector<int> c[nmax + 1];
vector<pair<int, int> > g[nmax + 1];
void dfs(int nod, int mtata) {
  viz[nod] = 1;
  d[nod] = inf;
  for (auto i : g[nod]) {
    if (i.second != mtata) {
      if (viz[i.first] == 0) {
        h[i.first] = h[nod] + 1;
        dfs(i.first, i.second);
        d[nod] = min(d[nod], d[i.first]);
      } else {
        d[nod] = min(d[nod], h[i.first]);
      }
    }
  }
}
void comp(int nod, int ind, int mtata) {
  viz[nod] = 1;
  for (auto i : g[nod]) {
    if (viz[i.first] == 0) {
      if (d[i.first] >= h[nod]) {
        ++nrc;
        c[nrc].push_back(i.second);
        comp(i.first, nrc, i.second);
      } else {
        c[ind].push_back(i.second);
        comp(i.first, ind, i.second);
      }
    } else if (i.second != mtata && h[i.first] < h[nod]) {
      c[ind].push_back(i.second);
    }
  }
}
int main() {
  int n, m;
  fscanf(stdin, "%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    fscanf(stdin, "%d%d", &x, &y);
    g[x].push_back({y, i});
    g[y].push_back({x, i});
    noduri[i][0] = x;
    noduri[i][1] = y;
  }
  for (int i = 1; i <= n; ++i) {
    if (viz[i] == 0) {
      dfs(i, 0);
    }
  }
  memset(viz, 0, sizeof(viz));
  nrc = 0;
  for (int i = 1; i <= n; ++i) {
    if (viz[i] == 0) {
      comp(i, 0, 0);
    }
  }
  vector<int> ans;
  for (int i = 1; i <= nrc; ++i) {
    int cnt = 0;
    sort(c[i].begin(), c[i].end());
    c[i].erase(unique(c[i].begin(), c[i].end()), c[i].end());
    m -= (int)c[i].size();
    for (auto j : c[i]) {
      for (int k = 0; k < 2; ++k) {
        int x = noduri[j][k];
        if (f[x] == 0) ++cnt;
        f[x] = 1;
      }
    }
    if (cnt == (int)c[i].size()) {
      for (auto j : c[i]) ans.push_back(j);
    }
    for (auto j : c[i]) {
      for (int k = 0; k < 2; ++k) {
        int x = noduri[j][k];
        f[x] = 0;
      }
    }
  }
  assert(m == 0);
  sort(ans.begin(), ans.end());
  fprintf(stdout, "%d\n", (int)ans.size());
  for (auto i : ans) fprintf(stdout, "%d ", i);
  return 0;
}
