#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
vector<int> graph[N];
int a[N], b[N];
set<int> bcc[N];
int dfn[N], low[N];
int piv = 1, par[N];
void dfs(int x, int p) {
  dfn[x] = low[x] = ++piv;
  par[x] = p;
  for (int i = 0; i < graph[x].size(); i++) {
    int id = graph[x][i];
    int w = a[id] ^ b[id] ^ x;
    if (w == p) continue;
    if (!dfn[w]) {
      dfs(w, x);
      low[x] = min(low[x], low[w]);
    } else {
      low[x] = min(low[x], dfn[w]);
    }
  }
}
map<pair<int, int>, int> G;
bool ban[N], vis[N];
int cpiv = 1, maxi[N];
vector<int> Edge[N];
void color(int x, int c) {
  if (c > 0) bcc[x].insert(c);
  vis[x] = 1;
  pair<int, int> temp;
  for (int i = 0; i < graph[x].size(); i++) {
    int id = graph[x][i];
    int w = a[id] ^ b[id] ^ x;
    if (vis[w]) {
      continue;
    }
    if (dfn[x] <= low[w]) {
      bcc[x].insert(++cpiv);
      color(w, cpiv);
    } else {
      color(w, c);
    }
  }
}
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    graph[a[i]].push_back(i);
    graph[b[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) dfs(i, 0);
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) color(i, 0);
  }
  vector<int> ret;
  for (int i = 1; i <= n; ++i) {
    if (bcc[i].size() == 1) {
      int color = *bcc[i].begin();
      for (int j = 0; j < graph[i].size(); ++j) {
        int id = graph[i][j];
        int w = a[id] ^ b[id] ^ i;
        if (bcc[w].count(color) &&
            (bcc[w].size() >= 2 || (bcc[w].size() == 1 && i < w))) {
          pair<int, int> temp = make_pair(w, color);
          int C = ++G[temp];
          maxi[color] = max(maxi[color], C);
          temp = make_pair(i, color);
          C = ++G[temp];
          maxi[color] = max(maxi[color], C);
          Edge[color].push_back(id);
        }
      }
    } else {
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (bcc[i].size() == 1) continue;
    for (int j = 0; j < graph[i].size(); ++j) {
      int id = graph[i][j];
      int w = a[id] ^ b[id] ^ i;
      if (bcc[w].size() >= 2 && (bcc[w].size() > bcc[i].size() ||
                                 (bcc[w].size() == bcc[i].size() && w < i))) {
        bool is = 0;
        for (auto it = bcc[i].begin(); it != bcc[i].end(); ++it)
          if (bcc[w].count(*it)) {
            int color = *it;
            pair<int, int> temp = make_pair(w, color);
            int C = ++G[temp];
            maxi[color] = max(maxi[color], C);
            temp = make_pair(i, color);
            C = ++G[temp];
            maxi[color] = max(maxi[color], C);
            Edge[color].push_back(id);
          }
      }
    }
  }
  for (int i = 1; i <= cpiv; ++i) {
    if (maxi[i] == 2) {
      for (int j = 0; j < Edge[i].size(); ++j) ret.push_back(Edge[i][j]);
    }
  }
  sort(ret.begin(), ret.end());
  cout << ret.size() << endl;
  for (int i = 0; i < ret.size(); ++i) printf("%d ", ret[i]);
  cout << endl;
  return 0;
}
