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 long long maxn = 2e5 + 500;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 500;
vector<long long> ger[maxn];
pair<long long, long long> yal[maxn];
bool vis[maxn];
long long s[maxn];
vector<long long> backe;
long long par[maxn];
long long epar[maxn];
long long h[maxn];
void dfs(long long a) {
  vis[a] = 1;
  for (auto e : ger[a]) {
    long long v = yal[e].first ^ yal[e].second ^ a;
    if (vis[v]) {
      if (h[v] < h[a] && abs(h[a] - h[v]) != 1) {
        backe.push_back(e);
        s[a]++;
        s[v]--;
      }
    } else {
      par[v] = a;
      epar[v] = e;
      h[v] = h[a] + 1;
      dfs(v);
    }
  }
}
void dfs_pr(long long a) {
  vis[a] = 1;
  for (auto e : ger[a]) {
    long long v = yal[e].first ^ yal[e].second ^ a;
    if (!vis[v]) {
      dfs_pr(v);
      s[a] += s[v];
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    ger[u].push_back(i);
    ger[v].push_back(i);
    yal[i] = make_pair(v, u);
  }
  for (long long i = 0; i < n; i++) {
    if (vis[i] == 0) {
      h[i] = 1;
      dfs(i);
    }
  }
  fill(vis, vis + maxn, 0);
  for (long long i = 0; i < n; i++) {
    if (vis[i] == 0) {
      dfs_pr(i);
    }
  }
  fill(vis, vis + maxn, 0);
  for (long long i = 0; i < n; i++) {
    if (s[i] != 1) {
      s[i] = 0;
    }
  }
  vector<long long> ans;
  for (auto e : backe) {
    long long v = yal[e].first;
    long long u = yal[e].second;
    if (h[v] < h[u]) {
      swap(v, u);
    }
    bool good = 1;
    while (v != u) {
      if (!s[v]) {
        good = 0;
        break;
      }
      v = par[v];
    }
    if (good) {
      v = yal[e].first;
      u = yal[e].second;
      if (h[v] < h[u]) {
        swap(v, u);
      }
      ans.push_back(e);
      while (v != u) {
        ans.push_back(epar[v]);
        v = par[v];
      }
    }
  }
  cout << ans.size() << endl;
  sort(ans.begin(), ans.end());
  for (auto e : ans) {
    cout << e + 1 << ' ';
  }
}
