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 double pai = acos(-1);
const double eps = 1e-10;
const long long mod = 1e9 + 7;
const int MXN = 1e6 + 5;
vector<pair<int, int> > g[MXN];
vector<int> bcc_arc[MXN];
vector<int> bcc[MXN];
int dfn[MXN];
int iscut[MXN];
int dfs_clock;
int bcc_clock;
int bccno[MXN];
struct no {
  int x, y, p;
};
stack<no> sk;
int tarjan(int u, int fa) {
  int lowu = dfn[u] = ++dfs_clock;
  int child = 0;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int to = g[u][i].first, num = g[u][i].second;
    no E = no{u, to, num};
    if (!dfn[to]) {
      sk.push(E);
      child++;
      int lowv = tarjan(to, u);
      lowu = min(lowu, lowv);
      if (lowv >= dfn[u]) {
        bcc_clock++;
        iscut[u] = 1;
        while (1) {
          no now = sk.top();
          sk.pop();
          bcc_arc[bcc_clock].push_back(now.p);
          if (bccno[now.x] != bcc_clock) {
            bcc[bcc_clock].push_back(now.x);
            bccno[now.x] = bcc_clock;
          }
          if (bccno[now.y] != bcc_clock) {
            bcc[bcc_clock].push_back(now.y);
            bccno[now.y] = bcc_clock;
          }
          if (now.x == u && now.y == to) break;
        }
      }
    } else if (to != fa && dfn[to] < dfn[u]) {
      lowu = min(lowu, dfn[to]);
      sk.push(E);
    }
  }
  if (fa < 0 && child == 1) iscut[u] = 0;
  return lowu;
}
void bccGet(int n) {
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i, -1);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int sa, sb;
    scanf("%d %d", &sa, &sb);
    g[sa].push_back(make_pair(sb, i));
    g[sb].push_back(make_pair(sa, i));
  }
  bccGet(n);
  vector<int> ans;
  for (int i = 1; i <= bcc_clock; i++) {
    if ((int)bcc[i].size() != (int)bcc_arc[i].size()) continue;
    for (int j = 0; j < (int)bcc_arc[i].size(); j++) {
      ans.push_back(bcc_arc[i][j]);
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << ' ';
  return 0;
}
