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 = 1e6 + 10, INF = 0x7fffffff;
int n, m;
map<int, int> w[maxn];
int pre[maxn], iscut[maxn], bccno[maxn], dfs_clock, bcc_cnt, num[maxn];
vector<int> G[maxn], bcc[maxn];
vector<int> f;
vector<int> g[maxn];
struct Edge {
  int u, v;
  Edge(int u, int v) : u(u), v(v) {}
};
stack<Edge> S;
int dfs(int u, int fa) {
  int lowu = pre[u] = ++dfs_clock;
  int child = 0;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    Edge e = Edge(u, v);
    if (!pre[v]) {
      S.push(e);
      child++;
      int lowv = dfs(v, u);
      lowu = min(lowu, lowv);
      if (lowv >= pre[u]) {
        iscut[u] = true;
        bcc_cnt++;
        bcc[bcc_cnt].clear();
        for (;;) {
          Edge x = S.top();
          S.pop();
          if (bccno[x.u] != bcc_cnt) {
            bcc[bcc_cnt].push_back(x.u);
            bccno[x.u] = bcc_cnt;
          }
          if (bccno[x.v] != bcc_cnt) {
            bcc[bcc_cnt].push_back(x.v);
            bccno[x.v] = bcc_cnt;
          }
          g[bcc_cnt].push_back(w[x.u][x.v]);
          if (x.u == u && x.v == v) break;
        }
      }
    } else if (pre[v] < pre[u] && v != fa) {
      S.push(e);
      lowu = min(lowu, pre[v]);
    }
  }
  if (fa < 0 && child == 1) iscut[u] = 0;
  return lowu;
}
void find_bcc() {
  memset(pre, 0, sizeof(pre));
  memset(iscut, 0, sizeof(iscut));
  memset(bccno, 0, sizeof(bccno));
  dfs_clock = bcc_cnt = 0;
  for (int i = 1; i <= n; i++)
    if (!pre[i]) dfs(i, -1);
}
int main() {
  int u, v;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    w[u][v] = w[v][u] = i;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  find_bcc();
  for (int i = 1; i <= bcc_cnt; i++) {
    if (g[i].size() == bcc[i].size())
      for (int j = 0; j < g[i].size(); j++) f.push_back(g[i][j]);
  }
  sort(f.begin(), f.end());
  cout << f.size() << endl;
  for (int i = 0; i < f.size(); i++) cout << f[i] << " ";
  cout << endl;
  return 0;
}
