2 0
 100000 0
 8 9
1 2
2 3
3 4
4 1
5 6
6 7
7 8
8 5
6 8
 2 1
1 2
 11 9
5 9
8 5
11 3
11 1
3 4
7 11
3 1
11 2
7 2
 7 9
7 3
7 4
1 2
2 3
3 1
3 4
4 5
5 6
6 4
 7 5
5 4
7 3
7 1
6 7
3 1
 7 8
1 2
2 3
3 4
4 1
3 5
5 6
6 7
7 3
 6 9
1 2
2 3
1 4
4 2
5 2
5 3
4 5
6 4
6 5
 7 9
1 2
2 4
4 3
3 1
2 3
4 5
5 6
6 7
7 4
 1 0
 6 7
1 2
2 3
3 1
3 4
4 5
5 6
6 4
 4 5
1 2
2 3
3 4
4 1
1 3
 100000 3
99998 99999
99999 100000
100000 99998

0

 0

 4
1 2 3 4 
 0

 6
3 4 6 7 8 9 
 9
1 2 3 4 5 6 7 8 9 
 3
2 3 5 
 8
1 2 3 4 5 6 7 8 
 0

 4
6 7 8 9 
 0

 6
1 2 3 5 6 7 
 0

 3
1 2 3 

#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 << ' ';
}
