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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 100000;
const int MAXM = 100000;
const int MAXCOMP = MAXN;
int n, m;
vector<int> adj[MAXN];
map<pair<int, int>, int> emp;
bool res[MAXM];
int ret[MAXM], nret;
int ncomp;
vector<int> comps[MAXN];
vector<int> compnodes[MAXCOMP];
vector<pair<int, int> > compedges[MAXCOMP];
bool done[MAXN];
int id[MAXN], mnid[MAXN], nid;
int nodestck[MAXN], nnodestck;
pair<int, int> edgestck[2 * MAXM];
int nedgestck;
void dfs(int at, int par) {
  id[at] = mnid[at] = nid++;
  nodestck[nnodestck++] = at;
  for (int i = (0); i < (((int)(adj[at]).size())); ++i) {
    int to = adj[at][i];
    if (!done[to]) edgestck[nedgestck++] = make_pair(at, to);
    if (to == par) continue;
    if (id[to] == -1) {
      dfs(to, at);
      mnid[at] = min(mnid[at], mnid[to]);
    } else {
      mnid[at] = min(mnid[at], id[to]);
    }
  }
  if (par != -1 && mnid[at] >= id[par] ||
      par == -1 && ((int)(adj[at]).size()) == 0) {
    int c = ncomp++;
    compnodes[c].clear(), compedges[c].clear();
    while (!done[at]) {
      int u = nodestck[--nnodestck];
      comps[u].push_back(c);
      compnodes[c].push_back(u);
      done[u] = true;
    }
    if (par != -1) comps[par].push_back(c), compnodes[c].push_back(par);
    if (par != -1)
      while (true) {
        pair<int, int> e = edgestck[--nedgestck];
        compedges[c].push_back(e);
        if (e.first != at && e.second == par)
          compedges[c].push_back(make_pair(e.second, e.first));
        if (e.first == par && e.second == at) break;
      }
  }
}
void run() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
    emp[make_pair(min(a, b), max(a, b))] = i;
  }
  ncomp = 0, nid = 0, nnodestck = 0, nedgestck = 0;
  for (int i = (0); i < (n); ++i) id[i] = -1, comps[i].clear(), done[i] = false;
  for (int i = (0); i < (n); ++i)
    if (!done[i]) dfs(i, -1);
  for (int i = (0); i < (m); ++i) res[i] = false;
  for (int i = (0); i < (ncomp); ++i) {
    if (((int)(compnodes[i]).size()) == 1) {
      assert(((int)(compedges[i]).size()) == 0);
      continue;
    }
    if (((int)(compnodes[i]).size()) == 2) {
      assert(((int)(compedges[i]).size()) == 2);
      continue;
    }
    if (((int)(compnodes[i]).size()) >= 3 &&
        ((int)(compedges[i]).size()) == ((int)(compnodes[i]).size()) * 2) {
      for (int j = (0); j < (((int)(compedges[i]).size())); ++j) {
        int a = compedges[i][j].first, b = compedges[i][j].second;
        if (a >= b) continue;
        assert(emp.count(make_pair(a, b)));
        res[emp[make_pair(a, b)]] = true;
      }
    }
  }
  nret = 0;
  for (int i = (0); i < (m); ++i)
    if (res[i]) ret[nret++] = i;
  printf("%d\n", nret);
  for (int i = (0); i < (nret); ++i) {
    if (i != 0) printf(" ");
    printf("%d", ret[i] + 1);
  }
  puts("");
}
int main() {
  run();
  return 0;
}
