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 = 2e5 + 15;
vector<int> graph[N];
int a[N], b[N];
set<int> bcc[N];
int dfn[N], low[N];
int piv = 1, par[N];
void dfs(int x, int p) {
  dfn[x] = low[x] = ++piv;
  par[x] = p;
  for (int i = 0; i < graph[x].size(); i++) {
    int id = graph[x][i];
    int w = a[id] ^ b[id] ^ x;
    if (w == p) continue;
    if (!dfn[w]) {
      dfs(w, x);
      low[x] = min(low[x], low[w]);
    } else {
      low[x] = min(low[x], dfn[w]);
    }
  }
}
map<pair<int, int>, int> G;
bool ban[N], vis[N];
int cpiv = 1, maxi[N];
vector<int> Edge[N];
void color(int x, int c) {
  if (c > 0) bcc[x].insert(c);
  vis[x] = 1;
  pair<int, int> temp;
  for (int i = 0; i < graph[x].size(); i++) {
    int id = graph[x][i];
    int w = a[id] ^ b[id] ^ x;
    if (vis[w]) {
      continue;
    }
    if (dfn[x] <= low[w]) {
      bcc[x].insert(++cpiv);
      color(w, cpiv);
    } else {
      color(w, c);
    }
  }
}
int main() {
  int n, m, x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    graph[a[i]].push_back(i);
    graph[b[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i)
    if (!dfn[i]) dfs(i, 0);
  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) color(i, 0);
  }
  vector<int> ret;
  for (int i = 1; i <= n; ++i) {
    if (bcc[i].size() == 1) {
      int color = *bcc[i].begin();
      for (int j = 0; j < graph[i].size(); ++j) {
        int id = graph[i][j];
        int w = a[id] ^ b[id] ^ i;
        if (bcc[w].count(color) &&
            (bcc[w].size() >= 2 || (bcc[w].size() == 1 && i < w))) {
          pair<int, int> temp = make_pair(w, color);
          int C = ++G[temp];
          maxi[color] = max(maxi[color], C);
          temp = make_pair(i, color);
          C = ++G[temp];
          maxi[color] = max(maxi[color], C);
          Edge[color].push_back(id);
        }
      }
    } else {
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (bcc[i].size() == 1) continue;
    for (int j = 0; j < graph[i].size(); ++j) {
      int id = graph[i][j];
      int w = a[id] ^ b[id] ^ i;
      if (bcc[w].size() >= 2 && (bcc[w].size() > bcc[i].size() ||
                                 (bcc[w].size() == bcc[i].size() && w < i))) {
        bool is = 0;
        for (auto it = bcc[i].begin(); it != bcc[i].end(); ++it)
          if (bcc[w].count(*it)) {
            int color = *it;
            pair<int, int> temp = make_pair(w, color);
            int C = ++G[temp];
            maxi[color] = max(maxi[color], C);
            temp = make_pair(i, color);
            C = ++G[temp];
            maxi[color] = max(maxi[color], C);
            Edge[color].push_back(id);
          }
      }
    }
  }
  for (int i = 1; i <= cpiv; ++i) {
    if (maxi[i] == 2) {
      for (int j = 0; j < Edge[i].size(); ++j) ret.push_back(Edge[i][j]);
    }
  }
  sort(ret.begin(), ret.end());
  cout << ret.size() << endl;
  for (int i = 0; i < ret.size(); ++i) printf("%d ", ret[i]);
  cout << endl;
  return 0;
}
