#include <bits/stdc++.h>
using namespace std;
const int arr = 3e5;
vector<pair<int, int> > vec[arr];
vector<int> add;
int deep[arr], ok[arr], use[arr];
int a[arr], b[arr], cnt[arr];
vector<pair<int, int> > ask[arr];
vector<pair<int, int> > cyc;
int pr[arr];
void dfs(int u, int pred) {
  use[u] = 1;
  pr[u] = pred;
  deep[u] = deep[pred] + 1;
  for (auto i : vec[u])
    if (i.first != pred) {
      if (use[i.first]) {
        if (deep[i.first] < deep[u]) add.push_back(i.second);
      } else
        dfs(i.first, u);
    }
}
void dfs2(int u, int pred) {
  use[u] = 1;
  for (auto i : vec[u])
    if (i.first != pred)
      if (!use[i.first]) {
        dfs2(i.first, u);
        cnt[u] += cnt[i.first];
      }
}
int get() {
  if (cyc.empty()) return (0);
  return (cyc.back().second);
}
void addd(int u) {
  if (u != 1)
    cyc.push_back({u, 0});
  else
    cyc.push_back({u, get() + 1});
}
void dell() { cyc.pop_back(); }
void dfs3(int u, int pred) {
  use[u] = 1;
  for (auto i : ask[u]) {
    if (get() >= i.first) ok[i.second] = 1;
  }
  for (auto i : vec[u])
    if (!use[i.first]) {
      addd(cnt[i.first]);
      dfs3(i.first, u);
      dell();
    }
}
map<pair<int, int>, int> mp;
signed main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    mp[{a[i], b[i]}] = i;
    mp[{b[i], a[i]}] = i;
    vec[a[i]].push_back({b[i], i});
    vec[b[i]].push_back({a[i], i});
  }
  for (int i = 1; i <= n; i++)
    if (!use[i]) dfs(i, 0);
  for (auto i : add) {
    if (deep[a[i]] < deep[b[i]]) swap(a[i], b[i]);
    cnt[a[i]]++;
    cnt[b[i]]--;
  }
  for (int i = 1; i <= n; i++) use[i] = 0;
  for (int i = 1; i <= n; i++)
    if (!use[i]) dfs2(i, 0);
  int cnt = 0;
  for (auto i : add) {
    ask[a[i]].push_back({deep[a[i]] - deep[b[i]], i});
  }
  for (int i = 1; i <= n; i++) use[i] = 0;
  for (int i = 1; i <= n; i++)
    if (!use[i]) dfs3(i, 0);
  vector<int> ans;
  for (auto i : add)
    if (ok[i]) {
      ans.push_back(i);
      while (a[i] != b[i]) {
        ans.push_back(mp[{a[i], pr[a[i]]}]);
        a[i] = pr[a[i]];
      }
    }
  cout << ans.size() << '\n';
  sort(ans.begin(), ans.end());
  for (auto i : ans) cout << i << ' ';
}
