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;
using namespace std::chrono;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
const int magic = 3;
void solve();
void dump(const vector<int>& a) {
  for (int i = 0; i < a.size(); i++) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
template <typename T, int N>
void dump(const array<T, N>& a) {
  for (int i = 0; i < a.size(); i++) {
    cerr << a[i] << ' ';
  }
  cerr << endl;
}
int main(int argc, char** argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
const int MX = 200500;
vector<pii> e[MX];
bool visited[MX];
int depth[MX];
struct cycle {
  int root{-1};
  vector<int> edges;
  bool is_simple{true};
};
int get_lc(int u, int v) {
  if (depth[u] < depth[v]) {
    return u;
  }
  return v;
}
void add_cycle(cycle& a, cycle& b) {
  if (b.root == -1) {
    return;
  }
  if (a.root == -1) {
    swap(a, b);
    return;
  }
  a.root = get_lc(a.root, b.root);
  a.is_simple = false;
  a.edges.clear();
}
vector<int> ans;
void add_ans(const vector<int>& sp) {
  for (auto w : sp) {
    ans.push_back(w);
  }
}
cycle dfs(int u, int pr, int edge_number) {
  visited[u] = true;
  depth[u] = depth[pr] + 1;
  cycle res;
  for (auto p : e[u]) {
    int v = p.first;
    if (v == pr) {
      continue;
    }
    if (visited[v]) {
      if (depth[v] > depth[u]) {
        continue;
      }
      cycle curr;
      curr.root = v;
      curr.edges.push_back(p.second);
      add_cycle(res, curr);
      continue;
    }
    auto r = dfs(v, u, p.second);
    add_cycle(res, r);
  }
  if (res.is_simple) {
    res.edges.push_back(edge_number);
    if (res.root == pr) {
      add_ans(res.edges);
    }
  }
  if (res.root == pr) {
    res = cycle();
  }
  return res;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    e[u].emplace_back(v, i);
    e[v].emplace_back(u, i);
  }
  for (int u = 0; u < n; u++) {
    if (!visited[u]) {
      dfs(u, u, -1);
    }
  }
  cout << ans.size() << "\n";
  sort(ans.begin(), ans.end());
  for (auto w : ans) {
    cout << w + 1 << ' ';
  }
  cout << "\n";
}
