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;
class DisjointSet {
 public:
  DisjointSet(int _n) : n(_n), parent(_n, 0), rank(_n, 0), cnts(_n, 1) {
    iota(parent.begin(), parent.end(), 0);
  }
  int find(int x) { return x == parent[x] ? x : (parent[x] = find(parent[x])); }
  void merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return;
    }
    if (rank[x] >= rank[y]) {
      parent[y] = x;
      if (rank[x] == rank[y]) {
        ++rank[x];
      }
      cnts[x] += cnts[y];
    } else {
      parent[x] = y;
      cnts[y] += cnts[x];
    }
  }
  int count(int x) { return cnts[find(x)]; }

 private:
  int n;
  vector<int> parent, rank, cnts;
};
class Solution {
 public:
  vector<int> findCycle(vector<pair<int, int>>& edges, int n, int m) {
    graph.clear();
    graph.resize(n);
    int idx = 0;
    map<pair<int, int>, int> indices;
    for (auto& e : edges) {
      int x = e.first, y = e.second;
      graph[x].push_back(y);
      graph[y].push_back(x);
      indices[make_pair(x, y)] = idx;
      indices[make_pair(y, x)] = idx;
      ++idx;
    }
    parent.clear();
    parent.resize(n, -1);
    bkParent.clear();
    bkParent.resize(n, -1);
    depth.clear();
    depth.resize(n, 0);
    color.clear();
    color.resize(n, -1);
    ids.clear();
    ids.resize(n + 100, -1);
    vector<int> path(n, -1);
    vector<int> res;
    for (int i = 0; i < n; ++i) {
      if (color[i] == 1) {
        continue;
      }
      ends.clear();
      dfs(i, -1, 0);
      DisjointSet ds(ends.size());
      for (int i = 0; i < ends.size(); ++i) {
        int u = ends[i].first, p = ends[i].second;
        int size = 0;
        while (depth[u] > depth[p]) {
          path[size++] = u;
          if (ids[u] == -1) {
            ids[u] = i;
          } else {
            ds.merge(i, ids[u]);
          }
          u = parent[u];
        }
        for (int j = 0; j < size; ++j) {
          int v = path[j];
          parent[v] = p;
        }
      }
      for (int i = 0; i < ends.size(); ++i) {
        if (ds.count(i) == 1) {
          int u = ends[i].first;
          int p = ends[i].second;
          res.emplace_back(indices[make_pair(u, p)]);
          while (depth[u] > depth[p]) {
            int pp = bkParent[u];
            res.emplace_back(indices[make_pair(pp, u)]);
            u = pp;
          }
        }
      }
    }
    sort(res.begin(), res.end());
    return res;
  }

 private:
  vector<vector<int>> graph;
  vector<int> parent;
  vector<int> bkParent;
  vector<int> depth;
  vector<int> color;
  vector<pair<int, int>> ends;
  vector<int> ids;
  void dfs(int u, int p, int d) {
    parent[u] = p;
    bkParent[u] = p;
    depth[u] = d;
    color[u] = 0;
    for (auto v : graph[u]) {
      if (v == p) {
        continue;
      }
      if (color[v] < 0) {
        dfs(v, u, d + 1);
      } else if (color[v] == 0) {
        ends.emplace_back(u, v);
      }
    }
    color[u] = 1;
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> edges;
  edges.reserve(m);
  for (int i = 0, u = 0, v = 0; i < m; ++i) {
    cin >> u >> v;
    edges.emplace_back(u - 1, v - 1);
  }
  auto res = sol.findCycle(edges, n, m);
  cout << res.size() << endl;
  for (auto r : res) {
    cout << r + 1 << " ";
  }
  cout << endl;
  return 0;
}
