#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> adj(100001);
int disc[100001], low[100001], tim;
struct edge {
  int x, y, ind;
};
vector<edge> s;
vector<int> ans;
void proses(vector<edge> &v) {
  set<int> s;
  int temp;
  for (int temp = 0; temp < v.size(); temp++) {
    s.insert(v[temp].x);
    s.insert(v[temp].y);
  }
  if (s.size() == v.size()) {
    for (temp = 0; temp < v.size(); temp++) {
      ans.push_back(v[temp].ind);
    }
  }
}
void dfs(int pos, int par) {
  disc[pos] = low[pos] = tim++;
  int child = 0;
  for (int temp = 0; temp < adj[pos].size(); temp++) {
    int thenode = adj[pos][temp].first, ind = adj[pos][temp].second;
    if ((thenode == par) ||
        ((disc[thenode] != -1) && (disc[thenode] > disc[pos])))
      continue;
    if (disc[thenode] == -1) {
      s.push_back({pos, thenode, ind});
      dfs(thenode, pos);
      child++;
      low[pos] = min(low[pos], low[thenode]);
    } else {
      s.push_back({pos, thenode, ind});
      low[pos] = min(low[pos], disc[thenode]);
    }
    if (((pos == par) && (child > 1)) ||
        ((pos != par) && (disc[pos] <= low[thenode]))) {
      vector<edge> edges;
      while (true) {
        int u = s.back().x, v = s.back().y, ind = s.back().ind;
        edges.push_back({u, v, ind});
        s.pop_back();
        if ((u == pos) && (v == thenode)) break;
      }
      proses(edges);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int temp, temp2;
  for (temp = 1; temp <= m; temp++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back({y, temp});
    adj[y].push_back({x, temp});
  }
  memset(disc, -1, sizeof(disc));
  for (temp = 1; temp <= n; temp++) {
    if (disc[temp] == -1) {
      dfs(temp, temp);
      proses(s);
      s.clear();
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << "\n";
  for (temp = 0; temp < ans.size(); temp++) {
    cout << ans[temp];
    if (temp != ans.size() - 1) cout << " ";
  }
  cout << "\n";
}
