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 + 5;
int n, m, idx[N], id, low[N], par[N];
bool good[N];
int org[N];
vector<int> g[N];
vector<pair<int, int> > rem, br;
bool edg[N];
void dfs(int u, int p) {
  bool art = 0;
  vector<int> adj;
  idx[u] = low[u] = ++id;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (!idx[v]) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
      if (low[v] >= idx[u]) {
        art = 1;
        adj.push_back(idx[v]);
      }
      if (low[v] > idx[u]) br.push_back({min(u, v), max(u, v)});
    } else if (v != p)
      low[u] = min(low[u], idx[v]);
  }
  if (!art) return;
  int prev = n + 1;
  n += adj.size();
  for (int i = prev; i <= n; i++) {
    org[i] = u;
  }
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i];
    if (v != p && low[v] >= idx[u]) {
      int in = upper_bound(adj.begin(), adj.end(), idx[v]) - adj.begin() - 1;
      rem.push_back({min(u, v), max(u, v)});
      g[prev + in].push_back(v);
      g[v].push_back(prev + in);
    }
  }
}
int fp(int u) { return (par[u] == u ? u : par[u] = fp(par[u])); }
int main() {
  scanf("%d%d", &n, &m);
  map<pair<int, int>, int> mp;
  for (int i = 0, a, b; i < m; i++) {
    scanf("%d%d", &a, &b);
    g[a].push_back(b);
    swap(a, b);
    g[a].push_back(b);
    mp[make_pair(min(a, b), max(a, b))] = i;
  }
  int orgN = n;
  for (int i = 1; i <= orgN; i++) {
    org[i] = i;
    if (!idx[i]) dfs(i, -1);
  }
  sort(rem.begin(), rem.end());
  sort(br.begin(), br.end());
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    good[i] = 1;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (binary_search(rem.begin(), rem.end(),
                        make_pair(min(i, g[i][j]), max(i, g[i][j]))) ||
          binary_search(br.begin(), br.end(),
                        make_pair(min(org[i], org[g[i][j]]),
                                  max(org[i], org[g[i][j]])))) {
        g[i][j] = g[i].back();
        g[i].pop_back();
        j--;
      } else {
        int a = i, b = g[i][j];
        int pa = fp(a), push_back = fp(b);
        par[pa] = push_back;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    good[fp(i)] &= (g[i].size() == 2);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (fp(i) == fp(g[i][j]) && good[fp(i)]) {
        int a = i, b = g[i][j];
        if (org[a]) a = org[a];
        if (org[b]) b = org[b];
        if (a > b) swap(a, b);
        ans++;
        edg[mp[make_pair(a, b)]] = 1;
      }
    }
  }
  cout << ans / 2 << endl;
  for (int i = 0; i < m; i++) {
    if (edg[i]) printf("%d ", i + 1);
  }
  return 0;
}
