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;
template <typename num_t>
inline void addmod(num_t& a, const long long& b, const int& m) {
  a = (a + b) % m;
  if (a < 0) a += m;
}
template <typename num_t>
inline void update_max(num_t& a, const num_t& b) {
  a = max(a, b);
}
template <typename num_t>
inline void update_min(num_t& a, const num_t& b) {
  a = min(a, b);
}
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) {
  return !lhs ? rhs : gcd(rhs % lhs, lhs);
}
template <typename num_t>
num_t pw(num_t n, num_t k, num_t mod) {
  long long res = 1;
  for (; k; k >>= 1) {
    if (k & 1) res = res * n % mod;
    n = 1ll * n * n % mod;
  }
  return (num_t)res;
}
const int inf = 1e9 + 7;
const long long ll_inf = 1ll * inf * inf;
const int MAX_N = 100000 + 7;
const int mod = inf;
int n, m;
vector<pair<int, int>> adj[MAX_N];
bool tree_edge[MAX_N];
bool check[MAX_N];
int nxt[MAX_N];
class DisjoinSet {
 public:
  vector<int> r;
  vector<int> cnt;
  int component;
  int nodes;
  void init(int n) {
    r.resize(n + 1);
    cnt.resize(n + 1);
    for (int j = 0; j < n + 1; ++j)
      if (!tree_edge[j]) cnt[j] = 1;
    fill(r.begin(), r.end(), -1);
    component = nodes = n;
  }
  int get(int u) { return r[u] < 0 ? u : r[u] = get(r[u]); }
  bool is_root(int u) {
    assert(u >= 0 && r.size());
    return u == get(u);
  }
  bool join(int u, int v) {
    u = get(u);
    v = get(v);
    if (u == v) return false;
    if (r[u] > r[v]) swap(u, v);
    r[u] += r[v];
    cnt[u] += cnt[v];
    r[v] = u;
    return true;
  }
  bool connected(int u, int v) { return get(u) == get(v); }
  int build(const vector<pair<int, int>>& edges) {
    component = nodes;
    for (const auto& edge : edges) {
      int u = edge.first;
      int v = edge.second;
      if (join(u, v)) {
        --component;
      }
    }
    for (const auto& edge : edges) {
      int u = edge.first, v = edge.second;
      r[u] = r[v] = -1;
    }
    return component;
  }
} dsu;
int depth[MAX_N];
int parent_edge[MAX_N];
void dfs(int u) {
  check[u] = true;
  for (auto& p : adj[u])
    if (!check[p.first]) {
      tree_edge[p.second] = true;
      int v = p.first;
      nxt[v] = u;
      depth[v] = depth[u] + 1;
      parent_edge[v] = p.second;
      dfs(v);
    }
}
vector<pair<int, int>> edge;
void solve() {
  cin >> n >> m;
  for (int i = (0), _b = (m); i < _b; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back({v, i});
    adj[v].push_back({u, i});
    edge.push_back({u, v});
  }
  for (int i = 1; i <= n; ++i)
    if (!nxt[i]) {
      nxt[i] = -1;
      dfs(i);
    }
  dsu.init(m);
  for (int j = 0; j < m; ++j)
    if (!tree_edge[j]) {
      int u = edge[j].first, v = edge[j].second;
      vector<int> temp;
      while (u != v) {
        if (depth[u] < depth[v]) swap(u, v);
        dsu.join(parent_edge[u], j);
        temp.push_back(u);
        u = nxt[u];
      }
      for (auto x : temp) nxt[x] = u;
    }
  vector<int> ans;
  for (int j = 0; j < m; ++j)
    if (dsu.cnt[dsu.get(j)] == 1 && -dsu.r[dsu.get(j)] >= 3) {
      ans.push_back(j + 1);
    }
  cout << ans.size() << '\n';
  for (int x : ans) cout << x << ' ';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test) cin >> test;
  for (int i = 0; i < test; ++i) {
    solve();
  }
}
