#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e5 + 50;
const long long mod = 1e9 + 7;
const long long base = maxn * 2;
long long low[maxn];
long long id[maxn];
long long cnt = 0;
long long cntnw = 0;
vector<long long> gr[maxn];
long long par[maxn];
pair<long long, long long> a[maxn];
vector<long long> adj[maxn];
bool dd[maxn];
long long sl[maxn];
stack<long long> st;
vector<long long> adj1[maxn];
long long anc[maxn][22];
long long n, m;
long long siz[maxn];
void dfs(long long u, long long par1) {
  dd[u] = 1;
  low[u] = id[u] = cnt++;
  st.push(u);
  for (auto to : adj[u]) {
    long long x = a[to].first;
    long long y = a[to].second;
    long long nxt = x + y - u;
    if (nxt == par1) continue;
    if (dd[nxt]) {
      low[u] = min(low[u], id[nxt]);
    } else {
      dfs(nxt, u);
      low[u] = min(low[u], low[nxt]);
      if (low[nxt] >= id[u]) {
        cntnw++;
        adj1[u].push_back(cntnw);
        siz[cntnw] = 1;
        vector<long long> vt;
        while (1) {
          long long p1 = st.top();
          st.pop();
          adj1[cntnw].push_back(p1);
          siz[cntnw]++;
          if (p1 == nxt) break;
        }
      }
    }
  }
}
vector<long long> topo;
bool kt[maxn];
void dfs1(long long u) {
  kt[u] = 1;
  for (auto to : adj1[u]) {
    if (kt[to]) continue;
    dfs1(to);
  }
  topo.push_back(u);
}
long long dep[maxn];
void dfs2(long long u, long long par) {
  anc[u][0] = par;
  kt[u] = 1;
  for (int i = 1; i < 20; i++) {
    anc[u][i] = anc[anc[u][i - 1]][i - 1];
  }
  for (auto to : adj1[u]) {
    if (kt[to]) continue;
    dep[to] = dep[u] + 1;
    dfs2(to, u);
  }
}
long long lca(long long x, long long y) {
  if (dep[x] < dep[y]) swap(x, y);
  long long kc = dep[x] - dep[y];
  for (int i = 20; i >= 0; i--) {
    if (kc & (1ll << i)) {
      x = anc[x][i];
    }
  }
  if (x == y) return x;
  for (int i = 20; i >= 0; i--) {
    if (anc[x][i] != anc[y][i]) {
      x = anc[x][i];
      y = anc[y][i];
    }
  }
  return anc[x][0];
}
long long lca1(long long x, long long y) {
  if (dep[x] < dep[y]) swap(x, y);
  long long kc = dep[x] - dep[y] - 1;
  for (int i = 20; i >= 0; i--) {
    if (kc & (1ll << i)) {
      x = anc[x][i];
    }
  }
  return x;
}
vector<long long> e[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  if (fopen("t.inp", "r")) {
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
  }
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> a[i].first >> a[i].second;
    adj[a[i].first].push_back(i);
    adj[a[i].second].push_back(i);
  }
  cntnw = n;
  for (int i = 1; i <= n; i++) {
    if (!dd[i]) {
      dfs(i, -1);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (!kt[i]) {
      dfs1(i);
    }
  }
  reverse(topo.begin(), topo.end());
  memset(kt, 0, sizeof(kt));
  for (auto to : topo) {
    if (kt[to]) continue;
    dfs2(to, 0);
  }
  for (int i = 1; i <= m; i++) {
    if (dep[a[i].first] < dep[a[i].second]) swap(a[i].first, a[i].second);
    long long l = lca(a[i].first, a[i].second);
    if (l == a[i].second) {
      e[lca1(a[i].first, a[i].second)].push_back(i);
    } else {
      e[l].push_back(i);
    }
  }
  vector<long long> ans;
  for (int i = n + 1; i <= cntnw; i++) {
    if (siz[i] == e[i].size()) {
      for (auto to : e[i]) {
        ans.push_back(to);
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (auto to : ans) {
    cout << to << " ";
  }
}
