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;
pair<vector<int>, vector<int>> order_and_low_link(vector<vector<int>> &ad) {
  int n = ad.size();
  vector<int> ord(n), low_link(n);
  vector<bool> ju(n);
  int cnt = 0;
  function<void(int, int)> dfs = [&](int cur, int par) {
    ord[cur] = low_link[cur] = cnt++;
    ju[cur] = true;
    for (int ch : ad[cur]) {
      if (ch == par) continue;
      if (ju[ch]) {
        low_link[cur] = min(low_link[cur], ord[ch]);
      } else {
        dfs(ch, cur);
        low_link[cur] = min(low_link[cur], low_link[ch]);
      }
    }
  };
  for (int i = 0; i < n; i++) {
    if (ju[i]) continue;
    dfs(i, -1);
  }
  return make_pair(ord, low_link);
}
vector<int> articulation_points(vector<vector<int>> &ad) {
  int n = ad.size();
  vector<int> ord(n), low_link(n), res;
  vector<bool> ju(n), art(n);
  int cnt = 0;
  function<void(int, int)> dfs = [&](int cur, int par) {
    ord[cur] = low_link[cur] = cnt++;
    ju[cur] = true;
    int chs = 0;
    for (int ch : ad[cur]) {
      if (ch == par) continue;
      if (ju[ch]) {
        low_link[cur] = min(low_link[cur], ord[ch]);
      } else {
        dfs(ch, cur);
        low_link[cur] = min(low_link[cur], low_link[ch]);
        if (par != -1 && ord[cur] <= low_link[ch]) art[cur] = true;
        chs++;
      }
    }
    if (par == -1 && chs >= 2) art[cur] = true;
  };
  for (int i = 0; i < n; i++) {
    if (!ju[i]) dfs(i, -1);
    if (art[i]) res.push_back(i);
  }
  return res;
}
vector<pair<int, int>> bridges(vector<vector<int>> &ad) {
  int n = ad.size();
  pair<vector<int>, vector<int>> p = order_and_low_link(ad);
  vector<int> &ord = p.first, low_link = p.second;
  vector<pair<int, int>> res;
  for (int i = 0; i < n; i++) {
    for (int ch : ad[i]) {
      if (ord[i] < low_link[ch]) res.push_back(make_pair(i, ch));
    }
  }
  return res;
}
vector<vector<pair<int, int>>> biconnected_component(vector<vector<int>> &ad) {
  int n = ad.size();
  vector<int> art = articulation_points(ad);
  vector<bool> is_art(n), ju(n);
  for (int i = 0; i < art.size(); i++) is_art[art[i]] = true;
  vector<vector<pair<int, int>>> res;
  vector<int> color(n, -1);
  int cnt = 0;
  function<void(int, int)> dfs = [&](int cur, int par) {
    color[cur] = cnt;
    if (is_art[cur]) {
      for (int ch : ad[cur]) {
        if (ch == par) continue;
        if (is_art[ch] && color[ch] == cnt) {
          res[cnt].push_back(make_pair(cur, ch));
        }
      }
      return;
    }
    ju[cur] = true;
    for (int ch : ad[cur]) {
      if (ch == par || ju[ch]) continue;
      res[cnt].push_back(make_pair(cur, ch));
    }
    for (int ch : ad[cur]) {
      if (ch == par || ju[ch]) continue;
      dfs(ch, cur);
    }
  };
  for (int i = 0; i < n; i++) {
    if (ju[i]) continue;
    if (is_art[i]) continue;
    res.push_back(vector<pair<int, int>>());
    dfs(i, -1);
    cnt++;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ad(n);
  map<pair<int, int>, int> mp;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    ad[a].push_back(b);
    ad[b].push_back(a);
    mp[{a, b}] = i;
    mp[{b, a}] = i;
  }
  vector<vector<pair<int, int>>> bcc = biconnected_component(ad);
  vector<int> cnt(n), res;
  for (int i = 0; i < bcc.size(); i++) {
    for (int j = 0; j < bcc[i].size(); j++) {
      cnt[bcc[i][j].first] = 0;
      cnt[bcc[i][j].second] = 0;
    }
    for (int j = 0; j < bcc[i].size(); j++) {
      cnt[bcc[i][j].first]++;
      cnt[bcc[i][j].second]++;
    }
    bool bo = true;
    for (int j = 0; j < bcc[i].size(); j++) {
      if (cnt[bcc[i][j].first] != 2) bo = false;
      if (cnt[bcc[i][j].second] != 2) bo = false;
    }
    if (bo) {
      for (int j = 0; j < bcc[i].size(); j++) {
        res.push_back(mp[bcc[i][j]]);
      }
    }
  }
  sort(res.begin(), res.end());
  cout << res.size() << "\n";
  for (int i = 0; i < res.size(); i++) cout << res[i] + 1 << " ";
  cout << "\n";
  return 0;
}
