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 N = 202020;
int n, m, tot;
int V[N], E[N];
vector<int> g[N], e[N];
namespace DCC {
const int N = ::N;
vector<int> key, dcc[N];
int dfn[N], low[N], st[N], _st, _;
void dfs(int c, int dep, const vector<int> g[]) {
  int cc = 0, out = 1 < dep;
  st[_st++] = c;
  dfn[c] = low[c] = dep;
  for (auto t : g[c])
    if (!dfn[t]) {
      dfs(t, dep + 1, g);
      low[c] = min(low[c], low[t]);
      if (low[t] >= dfn[c]) {
        if (++out == 2) key.push_back(c);
        while (st[--_st] != t) dcc[st[_st]].push_back(_);
        dcc[c].push_back(_);
        dcc[t].push_back(_++);
      }
    } else if (dfn[t] != dfn[c] - 1 || cc++)
      low[c] = min(low[c], dfn[t]);
}
int solve(int n, const vector<int> g[]) {
  fill_n(dfn, n, _ = 0);
  fill_n(low, n, _st = 0);
  fill_n(dcc, n, key = vector<int>());
  for (int i = (0); i < (n); ++i)
    if (!dfn[i]) dfs(i, 1, g);
  for (int i = (0); i < (n); ++i)
    if ((int)dcc[i].size() == 0) dcc[i].push_back(_++);
  return _;
}
}  // namespace DCC
void add(int u, int v) {
  --u, --v;
  g[u].push_back(v), g[v].push_back(u);
}
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  cin >> n >> m;
  for (int i = (1); i < (m + 1); ++i) {
    int u, v;
    cin >> u >> v;
    add(u, i + n);
    add(v, i + n);
  }
  tot = DCC::solve(n + m, g);
  for (int i = (0); i < (n + m); ++i) {
    for (auto t : DCC::dcc[i]) {
      if (i < n) {
        ++V[t];
      } else {
        ++E[t];
        e[t].push_back(i - n + 1);
      }
    }
  }
  vector<int> ans;
  for (int i = (0); i < (tot); ++i)
    if (V[i] == E[i]) {
      if (V[i] == 1) continue;
      for (auto u : e[i]) ans.push_back(u);
    }
  sort(ans.begin(), ans.end());
  cout << (int)ans.size() << "\n";
  for (int i = (0); i < ((int)ans.size()); ++i)
    cout << ans[i] << " \n"[i == (int)ans.size() - 1];
  return 0;
}
