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 = 1e5 + 10;
const int inf = 1e9 + 7;
int n, m;
int h[maxn];
int up[maxn];
int top[maxn];
bool mk[maxn];
int mark[maxn];
int getup[maxn];
vector<int> ans;
vector<int> adj[maxn];
vector<pair<pair<int, int>, int>> edge;
pair<int, pair<int, int>> tmp[4];
pair<int, pair<int, int>> down[maxn][2];
void in();
void solve();
void check(int);
void dfs(int);
void dfs2(int);
bool cmp(pair<pair<int, int>, int>, pair<pair<int, int>, int>);
void upd(int, pair<int, pair<int, int>>, pair<int, pair<int, int>>);
void out();
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  in();
  solve();
  out();
}
void in() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edge.push_back({{u, v}, i});
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
}
void solve() {
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      getup[i] = -1;
      dfs(i);
      dfs2(i);
    }
  }
  sort(edge.begin(), edge.end(), cmp);
  for (int i = 0; i < m; i++) {
    if (h[edge[i].first.first] < h[edge[i].first.second])
      swap(edge[i].first.first, edge[i].first.second);
    if (h[edge[i].first.first] - h[edge[i].first.second] == 1)
      top[edge[i].first.first] = i;
  }
  for (int i = 0; i < m; i++) check(i);
}
bool cmp(pair<pair<int, int>, int> A, pair<pair<int, int>, int> B) {
  pair<int, int> a = A.first;
  pair<int, int> b = B.first;
  if (h[a.first] < h[a.second]) swap(a.first, a.second);
  if (h[b.first] < h[b.second]) swap(b.first, b.second);
  int modea = h[a.first] - h[a.second];
  int modeb = h[b.first] - h[b.second];
  if (modea == modeb) return h[a.second] < h[b.second];
  return modea < modeb;
}
void check(int e) {
  int u = edge[e].first.second;
  int v = edge[e].first.first;
  bool fc = 0;
  if (h[v] - h[u] == 1) {
    bool ec = 0;
    if (down[v][0].first <= h[u] && down[v][1].first > h[u]) {
      if (down[v][0].first < h[u]) ec = 1;
      int U = down[v][0].second.first;
      int V = down[v][0].second.second;
      if (getup[U] - getup[V]) fc = 1;
    }
    if (ec && !mk[top[u]]) fc = 0;
  } else
    fc = mk[top[v]];
  if (fc) {
    mk[e] = 1;
    ans.push_back(edge[e].second + 1);
  }
}
void dfs(int u) {
  down[u][0] = {inf, {0, 0}};
  down[u][1] = {inf, {0, 0}};
  mark[u] = 1;
  for (auto v : adj[u]) {
    if (!mark[v]) {
      h[v] = h[u] + 1;
      dfs(v);
      upd(u, down[v][0], down[v][1]);
    } else if (h[u] - 1 > h[v]) {
      up[v]++;
      upd(u, {h[v], {u, v}}, {inf, {0, 0}});
    }
  }
}
void dfs2(int u) {
  mark[u] = 2;
  for (auto v : adj[u]) {
    if (mark[v] == 1) {
      getup[v] = getup[u] + up[u];
      dfs2(v);
    }
  }
}
void upd(int i, pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) {
  tmp[0] = a;
  tmp[1] = b;
  tmp[2] = down[i][0];
  tmp[3] = down[i][1];
  sort(tmp, tmp + 4);
  down[i][0] = tmp[0];
  down[i][1] = tmp[1];
}
void out() {
  sort(ans.begin(), ans.end());
  cout << ans.size() << '\n';
  for (auto x : ans) cout << x << ' ';
}
