#include <bits/stdc++.h>
using namespace std;
const double pai = acos(-1);
const double eps = 1e-10;
const long long mod = 1e9 + 7;
const int MXN = 1e6 + 5;
vector<pair<int, int> > g[MXN];
vector<int> bcc_arc[MXN];
vector<int> bcc[MXN];
int dfn[MXN];
int iscut[MXN];
int dfs_clock;
int bcc_clock;
int bccno[MXN];
struct no {
  int x, y, p;
};
stack<no> sk;
int tarjan(int u, int fa) {
  int lowu = dfn[u] = ++dfs_clock;
  int child = 0;
  for (int i = 0; i < (int)g[u].size(); i++) {
    int to = g[u][i].first, num = g[u][i].second;
    no E = no{u, to, num};
    if (!dfn[to]) {
      sk.push(E);
      child++;
      int lowv = tarjan(to, u);
      lowu = min(lowu, lowv);
      if (lowv >= dfn[u]) {
        bcc_clock++;
        iscut[u] = 1;
        while (1) {
          no now = sk.top();
          sk.pop();
          bcc_arc[bcc_clock].push_back(now.p);
          if (bccno[now.x] != bcc_clock) {
            bcc[bcc_clock].push_back(now.x);
            bccno[now.x] = bcc_clock;
          }
          if (bccno[now.y] != bcc_clock) {
            bcc[bcc_clock].push_back(now.y);
            bccno[now.y] = bcc_clock;
          }
          if (now.x == u && now.y == to) break;
        }
      }
    } else if (to != fa && dfn[to] < dfn[u]) {
      lowu = min(lowu, dfn[to]);
      sk.push(E);
    }
  }
  if (fa < 0 && child == 1) iscut[u] = 0;
  return lowu;
}
void bccGet(int n) {
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i, -1);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int sa, sb;
    scanf("%d %d", &sa, &sb);
    g[sa].push_back(make_pair(sb, i));
    g[sb].push_back(make_pair(sa, i));
  }
  bccGet(n);
  vector<int> ans;
  for (int i = 1; i <= bcc_clock; i++) {
    if ((int)bcc[i].size() != (int)bcc_arc[i].size()) continue;
    for (int j = 0; j < (int)bcc_arc[i].size(); j++) {
      ans.push_back(bcc_arc[i][j]);
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << ' ';
  return 0;
}
