#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";
}
