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;
struct edge {
  long long from;
  long long to;
  long long id;
};
vector<pair<long long, long long>> edgeList;
vector<long long> res;
vector<set<long long>> neighbour;
vector<vector<edge>> adjlist;
vector<edge> edgeStack;
vector<bool> isArt;
vector<int> d, low;
int counter, rootCount, root;
vector<vector<long long>> blocks;
void dfs(int v, int parent = -1) {
  d[v] = low[v] = ++counter;
  if (parent == root) ++rootCount;
  for (edge& e : adjlist[v]) {
    if (e.to != parent) {
      edgeStack.push_back(e);
    }
    if (!d[e.to]) {
      dfs(e.to, v);
      low[v] = min(low[v], low[e.to]);
      if (low[e.to] >= d[v]) {
        isArt[v] = true;
        blocks.push_back({});
        while (edgeStack.back().to != e.to || edgeStack.back().from != v) {
          blocks.back().push_back(edgeStack.back().id);
          edgeStack.pop_back();
        }
        blocks.back().push_back(edgeStack.back().id);
        edgeStack.pop_back();
      }
    } else if (e.to != parent && d[e.to] < low[v]) {
      low[v] = min(low[v], d[e.to]);
    }
  }
}
void findArticulationPoints() {
  counter = 0;
  low.resize(adjlist.size());
  d.assign(adjlist.size(), 0);
  isArt.assign(adjlist.size(), false);
  for (int v = 0; v < (int)adjlist.size(); v++) {
    if (!d[v]) {
      root = v;
      rootCount = 0;
      dfs(v);
      isArt[v] = rootCount > 1;
      if (!edgeStack.empty()) {
        blocks.push_back({});
        while (!edgeStack.empty()) {
          blocks.back().push_back(edgeStack.back().id);
          edgeStack.pop_back();
        }
      }
    }
  }
}
void checkBlock() {
  for (long long i = 0; i < blocks.size(); i++) {
    vector<vector<long long>> block(adjlist.size());
    set<long long> seen;
    for (long long x : blocks[i]) {
      seen.insert(edgeList[x].first);
      seen.insert(edgeList[x].second);
      block[edgeList[x].first].push_back(edgeList[x].second);
      block[edgeList[x].second].push_back(edgeList[x].first);
    }
    bool isSimple = true;
    for (long long x : seen) {
      isSimple &= block[x].size() == 2;
    }
    if (isSimple) {
      for (long long x : blocks[i]) {
        res.push_back(x);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, m;
  cin >> n >> m;
  neighbour.resize(n);
  adjlist.resize(n);
  edgeList.resize(m);
  for (long long i = 0; i < m; i++) {
    cin >> edgeList[i].first >> edgeList[i].second;
    edgeList[i].first--;
    edgeList[i].second--;
    neighbour[edgeList[i].first].insert(edgeList[i].second);
    adjlist[edgeList[i].first].push_back(
        {edgeList[i].first, edgeList[i].second, i});
    neighbour[edgeList[i].second].insert(edgeList[i].first);
    adjlist[edgeList[i].second].push_back(
        {edgeList[i].second, edgeList[i].first, i});
  }
  findArticulationPoints();
  checkBlock();
  sort(res.begin(), res.end());
  cout << res.size() << endl;
  for (auto x : res) {
    cout << (x + 1) << " ";
  }
  cout << endl;
}
