#include <bits/stdc++.h>
using namespace ::std;
const long long maxn = 2e5 + 500;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 500;
vector<long long> ger[maxn];
pair<long long, long long> yal[maxn];
bool vis[maxn];
long long s[maxn];
vector<long long> backe;
long long par[maxn];
long long epar[maxn];
long long h[maxn];
void dfs(long long a) {
  vis[a] = 1;
  for (auto e : ger[a]) {
    long long v = yal[e].first ^ yal[e].second ^ a;
    if (vis[v]) {
      if (h[v] < h[a] && abs(h[a] - h[v]) != 1) {
        backe.push_back(e);
        s[a]++;
        s[v]--;
      }
    } else {
      par[v] = a;
      epar[v] = e;
      h[v] = h[a] + 1;
      dfs(v);
    }
  }
}
void dfs_pr(long long a) {
  vis[a] = 1;
  for (auto e : ger[a]) {
    long long v = yal[e].first ^ yal[e].second ^ a;
    if (!vis[v]) {
      dfs_pr(v);
      s[a] += s[v];
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long v, u;
    cin >> v >> u;
    v--;
    u--;
    ger[u].push_back(i);
    ger[v].push_back(i);
    yal[i] = make_pair(v, u);
  }
  for (long long i = 0; i < n; i++) {
    if (vis[i] == 0) {
      h[i] = 1;
      dfs(i);
    }
  }
  fill(vis, vis + maxn, 0);
  for (long long i = 0; i < n; i++) {
    if (vis[i] == 0) {
      dfs_pr(i);
    }
  }
  fill(vis, vis + maxn, 0);
  for (long long i = 0; i < n; i++) {
    if (s[i] != 1) {
      s[i] = 0;
    }
  }
  vector<long long> ans;
  for (auto e : backe) {
    long long v = yal[e].first;
    long long u = yal[e].second;
    if (h[v] < h[u]) {
      swap(v, u);
    }
    bool good = 1;
    while (v != u) {
      if (!s[v]) {
        good = 0;
        break;
      }
      v = par[v];
    }
    if (good) {
      v = yal[e].first;
      u = yal[e].second;
      if (h[v] < h[u]) {
        swap(v, u);
      }
      ans.push_back(e);
      while (v != u) {
        ans.push_back(epar[v]);
        v = par[v];
      }
    }
  }
  cout << ans.size() << endl;
  sort(ans.begin(), ans.end());
  for (auto e : ans) {
    cout << e + 1 << ' ';
  }
}
