#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
int n, m;
int par[maxx], par_E[maxx], h[maxx], cnt[maxx];
bool mark[maxx];
vector<int> ans, Back_Edge, yal[maxx];
pair<int, int> Edge[maxx];
void DFS(int v) {
  mark[v] = true;
  for (auto e : yal[v]) {
    int u;
    int a = Edge[e].first;
    int b = Edge[e].second;
    if (a == v)
      u = b;
    else
      u = a;
    if (!mark[u]) {
      par[u] = v;
      par_E[u] = e;
      h[u] = h[v] + 1;
      DFS(u);
    } else {
      if (h[u] < h[v] && h[v] - h[u] != 1) {
        Back_Edge.push_back(e);
        cnt[v]++;
        cnt[u]--;
      }
    }
  }
}
void dfs(int v) {
  mark[v] = true;
  for (auto e : yal[v]) {
    int u;
    int a = Edge[e].first;
    int b = Edge[e].second;
    if (v == a)
      u = b;
    else
      u = a;
    if (!mark[u]) dfs(u), cnt[v] += cnt[u];
  }
}
void DFS_ALL(int t) {
  for (int i = 0; i < n; i++) {
    if (!mark[i] && t == 0)
      DFS(i);
    else if (!mark[i] && t == 1)
      dfs(i);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    yal[u].push_back(i);
    yal[v].push_back(i);
    Edge[i] = {u, v};
  }
  DFS_ALL(0);
  memset(mark, 0, sizeof mark);
  DFS_ALL(1);
  for (int i = 0; i < n; i++)
    if (cnt[i] != 1) cnt[i] = -1;
  for (auto i : Back_Edge) {
    int v = Edge[i].first;
    int u = Edge[i].second;
    if (h[u] < h[v]) swap(u, v);
    bool valid = true;
    while (u != v) {
      if (cnt[u] != 1) {
        valid = false;
        break;
      }
      u = par[u];
    }
    if (valid) {
      int v = Edge[i].first;
      int u = Edge[i].second;
      if (h[u] < h[v]) swap(u, v);
      ans.push_back(i);
      while (u != v) ans.push_back(par_E[u]), u = par[u];
    }
  }
  cout << (int)ans.size() << "\n";
  sort(ans.begin(), ans.end());
  for (auto i : ans) cout << i + 1 << " ";
  cout << "\n";
}
