#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
const int magic = 3;
void solve();
void dump(const vector<int>& a) {
  for (int i = 0; i < a.size(); i++) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
template <typename T, int N>
void dump(const array<T, N>& a) {
  for (int i = 0; i < a.size(); i++) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
const int MX = 200500;
vector<pii> e[MX];
bool visited[MX];
int depth[MX];
struct cycle {
  int root{-1};
  vector<int> edges;
  bool is_simple{true};
};
int get_lc(int u, int v) {
  if (depth[u] < depth[v]) {
    return u;
  }
  return v;
}
void add_cycle(cycle& a, cycle& b) {
  if (b.root == -1) {
    return;
  }
  if (a.root == -1) {
    swap(a, b);
    return;
  }
  a.root = get_lc(a.root, b.root);
  a.is_simple = false;
  a.edges.clear();
}
vector<int> ans;
void add_ans(const vector<int>& sp) {
  for (auto w : sp) {
    ans.push_back(w);
  }
}
cycle dfs(int u, int pr, int edge_number) {
  visited[u] = true;
  depth[u] = depth[pr] + 1;
  cycle res;
  for (auto p : e[u]) {
    int v = p.first;
    if (v == pr) {
      continue;
    }
    if (visited[v]) {
      if (depth[v] > depth[u]) {
        continue;
      }
      cycle curr;
      curr.root = v;
      curr.edges.push_back(p.second);
      add_cycle(res, curr);
      continue;
    }
    auto r = dfs(v, u, p.second);
    add_cycle(res, r);
  }
  if (res.is_simple) {
    res.edges.push_back(edge_number);
    if (res.root == pr) {
      add_ans(res.edges);
    }
  }
  if (res.root == pr) {
    res = cycle();
  }
  return res;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    e[u].emplace_back(v, i);
    e[v].emplace_back(u, i);
  }
  for (int u = 0; u < n; u++) {
    if (!visited[u]) {
      dfs(u, u, -1);
    }
  }
  cout << ans.size() << "\n";
  sort(ans.begin(), ans.end());
  for (auto w : ans) {
    cout << w + 1 << ' ';
  }
  cout << "\n";
}
