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 int maxn = 100500;
int parent[maxn], sz[maxn], lev[maxn], p[maxn], cp[maxn], id[maxn], sz_c[maxn],
    ed[maxn];
bool in[maxn];
vector<pair<int, int> > g[maxn];
vector<pair<pair<int, int>, int> > back_ed;
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
  parent[v] = v;
  sz[v] = 1;
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (sz[a] < sz[b]) swap(a, b);
    parent[b] = a;
    sz[a] += sz[b];
  }
}
void init(int u, int par = 0, int lvl = 0, int edge = -1) {
  lev[u] = lvl;
  p[u] = cp[u] = par;
  ed[u] = edge;
  in[u] = true;
  for (auto v : g[u]) {
    if (v.first == par) continue;
    if (p[v.first] == -1)
      init(v.first, u, lvl + 1, v.second);
    else if (in[v.first])
      back_ed.push_back({{u, v.first}, v.second});
  }
  in[u] = false;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back({v, i + 1});
    g[v].push_back({u, i + 1});
  }
  for (int i = 0; i < n; ++i) p[i] = id[i] = -1;
  for (int i = 0; i < n; ++i)
    if (p[i] == -1) init(i);
  for (int i = 0; i < (int)back_ed.size(); ++i) make_set(i);
  for (int i = 0; i < (int)back_ed.size(); ++i) {
    int u, v;
    tie(u, v) = back_ed[i].first;
    int cur = u;
    while (lev[cur] > lev[v]) {
      if (id[cur] == -1)
        id[cur] = i;
      else
        union_sets(id[cur], i);
      int tmp = cur;
      cur = p[cur];
      p[tmp] = v;
    }
  }
  for (int i = 0; i < (int)back_ed.size(); ++i) sz_c[find_set(i)]++;
  vector<int> ans;
  for (int i = 0; i < (int)back_ed.size(); ++i)
    if (sz_c[find_set(i)] == 1) {
      int u, v;
      tie(u, v) = back_ed[i].first;
      ans.push_back(back_ed[i].second);
      int cur = u;
      while (cur != v) {
        ans.push_back(ed[cur]);
        cur = cp[cur];
      }
    }
  cout << (int)ans.size() << '\n';
  sort(ans.begin(), ans.end());
  for (auto e : ans) cout << e << ' ';
  cout << '\n';
  return 0;
}
