#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<pair<int, int> > son[N];
vector<int> bcc_node[N], bcc_edge[N], ans;
stack<pair<pair<int, int>, int> > s;
int bcc_cnt, belong[N], is_cnt[N], now_time, dfn[N], low[N];
void dfs(int o, int fa) {
  dfn[o] = low[o] = ++now_time;
  int ch = 0;
  for (int i = 0; i < son[o].size(); ++i) {
    int v = son[o][i].first;
    if (v == fa) continue;
    pair<pair<int, int>, int> edge = {{o, v}, son[o][i].second};
    if (!dfn[v]) {
      s.push(edge);
      dfs(v, o);
      low[o] = min(low[o], low[v]);
      if (low[v] >= dfn[o]) {
        ch++, is_cnt[o] = true;
        bcc_node[++bcc_cnt].clear();
        bcc_edge[bcc_cnt].clear();
        while (true) {
          pair<pair<int, int>, int> now = s.top();
          s.pop();
          bcc_edge[bcc_cnt].push_back(now.second);
          if (belong[now.first.first] != bcc_cnt)
            belong[now.first.first] = bcc_cnt,
            bcc_node[bcc_cnt].push_back(now.first.first);
          if (belong[now.first.second] != bcc_cnt)
            belong[now.first.second] = bcc_cnt,
            bcc_node[bcc_cnt].push_back(now.first.second);
          if (now.first.first == o && now.first.second == v) break;
        }
      }
    } else if (dfn[v] < dfn[o]) {
      s.push(edge);
      low[o] = min(dfn[v], low[o]);
    }
  }
  if (!fa && ch == 1) is_cnt[o] = false;
}
int main() {
  int n, m;
  int u, v;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    son[u].push_back(make_pair(v, i));
    son[v].push_back(make_pair(u, i));
  }
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) dfs(i, 0);
  int tot = 0;
  set<int> as;
  for (int i = 1; i <= bcc_cnt; ++i) {
    if (bcc_node[i].size() == bcc_edge[i].size()) {
      for (int j = 0; j < bcc_node[i].size(); ++j)
        as.insert(bcc_edge[i][j]), tot++;
    }
  }
  printf("%d\n", tot);
  for (int i : as) printf("%d ", i);
  return 0;
}
