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;
vector<pair<int, int> > g[600001];
bool vis[600001];
vector<int> vbel[600001];
int dfn[600001], low[600001], ebel[600001], dfc, vbcc;
int dfs_vbcc(int u, int f) {
  static int s[600001];
  static int t;
  s[++t] = u;
  dfn[u] = low[u] = ++dfc;
  for (pair<int, int> p : g[u]) {
    int v = p.first, i = p.second;
    if (vis[i]) continue;
    vis[i] = 1;
    s[++t] = -i;
    if (!dfn[v]) {
      low[u] = min(low[u], dfs_vbcc(v, i));
      if (dfn[u] <= low[v]) {
        for (++vbcc; s[t + 1] != -i; --t)
          s[t] > 0 ? vbel[s[t]].push_back(vbcc), 0 : ebel[-s[t]] = vbcc;
        vbel[u].push_back(vbcc);
      }
    } else
      low[u] = min(low[u], dfn[v]);
  }
  return low[u];
}
void tarjan_vbcc(int n, int m) {
  dfc = vbcc = 0;
  fill_n(vis + 1, m, 0);
  fill_n(ebel + 1, m, 0);
  fill_n(dfn + 1, n, 0);
  for (int u = 1; u <= n; ++u) vbel[u].resize(0);
  for (int u = 1; u <= n; ++u)
    if (!dfn[u]) dfs_vbcc(u, 0);
}
int ew[600001], vcnt[600001], ecnt[600001];
vector<int> ansv[600001];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v, i);
    g[v].emplace_back(u, i);
  }
  tarjan_vbcc(n, m);
  for (int i = 1; i <= n; ++i)
    for (int b : vbel[i]) vcnt[b]++;
  for (int i = 1; i <= m; ++i) ecnt[ebel[i]]++, ansv[ebel[i]].push_back(i);
  vector<int> ans;
  ans.reserve(m);
  for (int i = 1; i <= vbcc; ++i)
    if (vcnt[i] == ecnt[i])
      ans.insert(ans.end(), ansv[i].begin(), ansv[i].end());
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int ei : ans) cout << ei << ' ';
  cout << endl;
  return 0;
}
