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 maxn = 1e5 + 10;
vector<int> v[maxn];
bool vis[maxn];
int pre[maxn], low[maxn];
int ile[maxn];
int deg[maxn];
set<pair<pair<int, int>, int> > zbior;
stack<int> stos;
stack<pair<int, int> > stosE;
int nr;
vector<int> res;
void checkbc(vector<int> &v, vector<pair<int, int> > &e) {
  for (int b : v) deg[b] = 0;
  for (pair<int, int> x : e) {
    deg[x.first]++;
    deg[x.second]++;
  }
  for (int b : v) {
    if (deg[b] != 2) return;
  }
  for (pair<int, int> x : e) {
    auto it = zbior.upper_bound({{x.first, x.second}, 0});
    res.push_back(it->second);
  }
}
void dfs(int a, int p) {
  vis[a] = true;
  pre[a] = nr++;
  int res = pre[a];
  bool czy = true;
  for (int b : v[a]) {
    if (b == p) continue;
    if (vis[b] == false) {
      stos.push(a);
      stosE.push({a, b});
      dfs(b, a);
      if (low[b] >= pre[a]) {
        vector<int> v;
        vector<pair<int, int> > e;
        while (true) {
          int c = stos.top();
          stos.pop();
          v.push_back(c);
          if (c == a) break;
        }
        while (true) {
          pair<int, int> c = stosE.top();
          stosE.pop();
          e.push_back(c);
          if (c.first == a && c.second == b) break;
        }
        checkbc(v, e);
      } else
        czy = false;
      res = min(res, low[b]);
    } else
      res = min(res, pre[b]);
    if (pre[b] < pre[a]) stosE.push({a, b});
  }
  low[a] = res;
  if (czy) stos.push(a);
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
    zbior.insert({{a, b}, i + 1});
    zbior.insert({{b, a}, i + 1});
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      dfs(i, 0);
    }
  }
  cout << res.size() << "\n";
  sort(res.begin(), res.end());
  for (int b : res) cout << b << " ";
  cout << "\n";
  return 0;
}
