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 T>
auto operator<<(ostream& out, T& container)
    -> decltype(container.begin(), container.end(), out) {
  bool first = true;
  out << "[";
  for (auto it = container.begin(); it != container.end(); ++it) {
    if (!first) out << ", ";
    out << *it;
    first = false;
  }
  return out << "]";
}
int n, m;
vector<pair<int, int>> e[100000];
bool usededge[100000];
bool isroot[100000];
int ind[100000], low[100000];
int counter = 0;
vector<int> res;
void tarjan(int u) {
  ind[u] = low[u] = counter++;
  vector<pair<int, int>> ne;
  for (auto a : e[u]) {
    int v = a.first;
    if (usededge[a.second]) continue;
    usededge[a.second] = true;
    ne.push_back(a);
    if (ind[v] == -1) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else {
      low[u] = min(low[u], ind[v]);
    }
  }
  e[u] = ne;
}
bool calc(int u, bool good) {
  vector<pair<int, int>> newstarts, continues, bridges;
  int back = -1;
  int backcount = 0;
  for (auto a : e[u]) {
    int v = a.first;
    if (ind[v] < ind[u]) {
      backcount++;
      back = a.second;
    } else {
      if (low[v] < ind[u])
        continues.push_back(a);
      else if (low[v] == ind[u])
        newstarts.push_back(a);
      else
        bridges.push_back(a);
    }
  }
  for (auto a : bridges) {
    int v = a.first;
    calc(v, true);
  }
  for (auto a : newstarts) {
    int v = a.first;
    if (calc(v, true)) res.push_back(a.second);
  }
  if (continues.size() == 0) {
    if (good && backcount == 1) {
      res.push_back(back);
      return true;
    } else
      return false;
  } else if (continues.size() + backcount == 1) {
    if (calc(continues[0].first, good)) {
      res.push_back(continues[0].second);
      return true;
    }
    return false;
  } else
    for (auto a : continues) {
      calc(a.first, false);
      return false;
    }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    e[a].push_back({b, i});
    e[b].push_back({a, i});
  }
  for (int i = 0; i < n; ++i) ind[i] = low[i] = -1;
  for (int i = 0; i < n; ++i) {
    if (ind[i] != -1) continue;
    isroot[i] = true;
    tarjan(i);
  }
  for (int i = 0; i < n; ++i) {
    if (!isroot[i]) continue;
    calc(i, true);
  }
  sort(res.begin(), res.end());
  cout << res.size() << "\n";
  for (int a : res) cout << a + 1 << " ";
  cout << "\n";
}
