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 = 1e5 + 5;
vector<pair<int, int>> edges[N], tree_edge[N], back_edge[N], v;
vector<array<int, 3>> ans[N];
priority_queue<array<int, 3>> pq;
bool vis[N];
int back_edges_ending_at[N], dp[N], D[N];
void dfs_tree(int node, int p, int d = 0) {
  vis[node] = 1;
  D[node] = d;
  for (auto elm : edges[node]) {
    if (elm.first == p) continue;
    if (!vis[elm.first]) {
      dfs_tree(elm.first, node, d + 1);
      tree_edge[node].push_back(elm);
    } else if (D[elm.first] < D[node]) {
      back_edge[node].push_back(elm);
      back_edges_ending_at[elm.first]++;
    }
  }
}
void dfs_dp(int a, int p) {
  dp[a] = back_edge[a].size() - back_edges_ending_at[a];
  for (auto elm : tree_edge[a]) {
    if (elm.first == p) continue;
    dfs_dp(elm.first, a);
    dp[a] += dp[elm.first];
  }
}
int cnt = 0;
void dfs_ans(int a, int id, int p) {
  for (auto elm : tree_edge[a]) {
    if (elm.first == p) continue;
    dfs_ans(elm.first, elm.second, a);
  }
  for (int i = 0; i < back_edges_ending_at[a]; i++) pq.pop();
  for (int i = 0; i < back_edge[a].size(); i++) {
    cnt++;
    int idi = back_edge[a][i].second;
    int m = D[back_edge[a][i].first];
    pq.push({m, cnt, idi});
    ans[idi].push_back({idi, D[a], 1});
  }
  if (pq.size()) {
    int idi = pq.top()[2];
    if (ans[idi].back()[1] > D[a] - 1)
      ans[idi].push_back({id, D[a] - 1, dp[a]});
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    edges[x].push_back({y, i}), edges[y].push_back({x, i});
    v.push_back({x, y});
  }
  for (int i = 1; i < n + 1; i++) {
    if (vis[i]) {
      continue;
    }
    dfs_tree(i, -1);
    dfs_dp(i, -1);
    dfs_ans(i, 0, -1);
  }
  vector<int> v1;
  for (int i = 0; i < m; i++) {
    if (!ans[i].size()) continue;
    int id = ans[i][0][0];
    int len = abs(D[v[id].first] - D[v[id].second]) + 1;
    if (ans[i].size() != len) continue;
    bool b = 1;
    for (int j = 0; j < ans[i].size(); j++) {
      if (ans[i][j][2] != 1) b = 0;
      if (j && (abs(ans[i][j][1] - ans[i][j - 1][1]) != 1)) b = 0;
    }
    for (int j = 0; (j < ans[i].size()) && b; j++) {
      v1.push_back(ans[i][j][0] + 1);
    }
  }
  sort(v1.begin(), v1.end());
  cout << v1.size() << '\n';
  for (auto elm : v1) {
    cout << elm << ' ';
  }
  return 0;
}
