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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long maxn = 3e6;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
int n, m;
vector<pair<pair<int, int>, int> > e;
vector<int> adj[maxn], ans;
int mark[maxn];
int h[maxn], par[maxn];
int a[maxn], prt[maxn];
int sum[maxn];
vector<int> ord;
void dfs(int v) {
  ord.push_back(v), mark[v] = 1;
  for (auto u : adj[v])
    if (!mark[u]) par[u] = v, h[u] = h[v] + 1, dfs(u);
}
void calc(int v) {
  mark[v] = 2;
  for (auto u : adj[v])
    if (mark[u] != 2) prt[v] += prt[u] + a[u], calc(u);
}
void hentai(int v) {
  mark[v] = 3;
  for (auto u : adj[v])
    if (mark[u] != 3) sum[u] = prt[v] + sum[v], hentai(u);
}
bool can[maxn];
void solve(int v) {
  ord.clear();
  dfs(v);
  for (auto u : adj[v]) {
    if (h[u] < h[v] and u != par[v]) a[v]++, a[u]--;
  }
  calc(v);
  hentai(v);
  for (int i : ord) a[i] = 0;
  for (auto u : adj[v]) {
    if (h[u] < h[v] and u != par[v]) {
      if (sum[v] - sum[u] > h[v] - h[u]) a[v] -= 1e6, a[u] += 1e6;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    if (u > v) swap(u, v);
    adj[u].push_back(v);
    adj[v].push_back(u);
    e.push_back({{u, v}, i});
  }
  sort(e.begin(), e.end());
  for (int i = 1; i <= n; i++)
    if (!mark[i]) solve(i);
  cout << ans.size() << '\n';
  for (int i : ans) cout << i << ' ';
  return (0);
}
