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 = 100005;
vector<int> G[MAXN];
vector<int> grafo[MAXN];
struct edge {
  int u, v, comp;
  bool bridge;
};
vector<edge> e;
void addEdge(int u, int v) {
  G[u].push_back(e.size()), G[v].push_back(e.size());
  e.push_back((edge){u, v, -1, false});
}
int V[MAXN], L[MAXN], P[MAXN], comp[MAXN];
int qV, nbc;
void initDfs(int n) {
  for (int i = (0); i < (MAXN); i++) G[i].clear();
  memset(G, 0, sizeof(G)), memset(V, 0, sizeof(V)), memset(L, 0, sizeof(L)),
      memset(comp, 0, sizeof(comp)), memset(P, 0, sizeof(P));
  e.clear();
  for (int i = (0); i < (n); i++) V[i] = -1;
  nbc = qV = 0;
}
stack<int> st;
void dfs(int u, int pe) {
  L[u] = V[u] = qV++;
  comp[u] = (pe != -1);
  for (auto &ne : G[u])
    if (ne != pe) {
      int v = e[ne].u ^ e[ne].v ^ u;
      if (V[v] == -1) {
        st.push(ne);
        dfs(v, ne);
        if (L[v] > V[u]) {
          e[ne].bridge = true;
        }
        P[u] += (L[v] >= V[u]);
        if (L[v] >= V[u]) {
          int last;
          do {
            last = st.top();
            st.pop();
            e[last].comp = nbc;
          } while (last != ne);
          nbc++;
          comp[u]++;
        }
        L[u] = min(L[u], L[v]);
      } else if (V[v] < V[u]) {
        st.push(ne);
        L[u] = min(L[u], V[v]);
      }
    }
}
set<int> C[2 * MAXN];
int compnodo[MAXN];
int ptoart;
void blockcuttree() {
  memset(compnodo, 0, sizeof(compnodo));
  ptoart = 0;
  for (int i = (0); i < (2 * MAXN); i++) C[i].clear();
  for (auto &it : e) {
    vector<int> nodos = {it.u, it.v};
    for (int u : nodos) {
      if (comp[u] == 1)
        compnodo[u] = it.comp;
      else {
        if (compnodo[u] == 0) {
          compnodo[u] = nbc + ptoart;
          ptoart++;
        }
        C[it.comp].insert(compnodo[u]);
        C[compnodo[u]].insert(it.comp);
      }
    }
  }
}
map<pair<int, int>, int> id_eje;
map<pair<int, int>, int> eje_componente;
bool visitado[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  initDfs(n + 1);
  for (int i = (0); i < (m); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    id_eje[{a, b}] = i + 1;
    id_eje[{b, a}] = i + 1;
    grafo[a].push_back(b);
    grafo[b].push_back(a);
    addEdge(a, b);
  }
  for (int i = (0); i < (n); i++) {
    if (V[i] == -1) {
      dfs(i, -1);
    }
  }
  vector<edge> ejesPorComponente[nbc];
  for (auto &eje : e) {
    eje_componente[{eje.u, eje.v}] = eje.comp;
    eje_componente[{eje.v, eje.u}] = eje.comp;
    ejesPorComponente[eje.comp].push_back(eje);
  }
  vector<int> res;
  for (int i = (0); i < (nbc); i++) {
    if ((int)(ejesPorComponente[i]).size() <= 2) continue;
    bool simple = true;
    map<int, int> apariciones_por_nodo;
    for (auto &eje : ejesPorComponente[i]) {
      apariciones_por_nodo[eje.u]++;
      apariciones_por_nodo[eje.v]++;
      if (apariciones_por_nodo[eje.u] > 2 || apariciones_por_nodo[eje.v] > 2) {
        simple = false;
        break;
      }
    }
    if (simple) {
      for (auto &eje : ejesPorComponente[i]) {
        res.push_back(id_eje[{eje.u, eje.v}]);
      }
    }
  }
  sort(res.begin(), res.end());
  cout << (int)(res).size() << "\n";
  for (auto it = res.begin(); it != res.end(); it++) {
    cout << *it << " ";
  }
  cout << "\n";
}
