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 double PI = acos(-1);
template <typename T>
T getint() {
  T val = 0;
  char c;
  bool neg = false;
  while ((c = getchar()) && !(c >= '0' && c <= '9')) {
    neg |= c == '-';
  }
  do {
    val = (val * 10) + c - '0';
  } while ((c = getchar()) && (c >= '0' && c <= '9'));
  return val * (neg ? -1 : 1);
}
using namespace std;
class Edge {
 public:
  int u;
  int v;
  int ind;
  Edge(int u, int v, int ind);
};
Edge::Edge(int u, int v, int ind) {
  this->u = u;
  this->v = v;
  this->ind = ind;
}
class Graph {
  int V;
  int E;
  list<pair<int, int>> *adj;
  void BCCUtil(int u, int disc[], int low[], list<Edge> *st, int parent[]);

 public:
  Graph(int V);
  void addEdge(int v, int w, int ind);
  void BCC();
  void handle();
};
Graph::Graph(int V) {
  this->V = V;
  this->E = 0;
  adj = new list<pair<int, int>>[V];
}
void Graph::addEdge(int v, int w, int ind) {
  adj[v].push_back({w, ind});
  E++;
}
set<int> ans;
vector<Edge> akt;
void Graph::handle() {
  map<int, int> fokszam;
  for (auto i : akt) {
    fokszam[i.u]++;
    fokszam[i.v]++;
  }
  bool ok = true;
  for (auto i : fokszam) {
    ok &= i.second == 2;
  }
  if (ok) {
    for (auto i : akt) {
      ans.insert(i.ind + 1);
    }
  }
}
void Graph::BCCUtil(int u, int disc[], int low[], list<Edge> *st,
                    int parent[]) {
  static int time = 0;
  disc[u] = low[u] = ++time;
  int children = 0;
  list<pair<int, int>>::iterator i;
  for (i = adj[u].begin(); i != adj[u].end(); ++i) {
    int v = i->first;
    if (disc[v] == -1) {
      children++;
      parent[v] = u;
      st->push_back(Edge(u, v, i->second));
      BCCUtil(v, disc, low, st, parent);
      low[u] = min(low[u], low[v]);
      if ((disc[u] == 1 && children > 1) ||
          (disc[u] > 1 && low[v] >= disc[u])) {
        while (st->back().u != u || st->back().v != v) {
          akt.push_back(st->back());
          st->pop_back();
        }
        akt.push_back(st->back());
        handle();
        st->pop_back();
      }
    } else if (v != parent[u] && disc[v] < low[u]) {
      low[u] = min(low[u], disc[v]);
      st->push_back(Edge(u, v, i->second));
    }
  }
}
void Graph::BCC() {
  int *disc = new int[V];
  int *low = new int[V];
  int *parent = new int[V];
  list<Edge> *st = new list<Edge>[E];
  for (int i = 0; i < V; i++) {
    disc[i] = -1;
    low[i] = -1;
    parent[i] = -1;
  }
  for (int i = 0; i < V; i++) {
    if (disc[i] == -1) BCCUtil(i, disc, low, st, parent);
    int j = 0;
    while (st->size() > 0) {
      j = 1;
      akt.push_back(st->back());
      st->pop_back();
    }
    if (j == 1) {
      handle();
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  Graph g(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    g.addEdge(a - 1, b - 1, i);
    g.addEdge(b - 1, a - 1, i);
  }
  g.BCC();
  cout << (int)(ans).size() << "\n";
  for (auto i : ans) {
    cout << i << " ";
  }
  cout << "\n";
  return 0;
}
