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;
int root[100010];
int cnt;
int high[100010];
bool treeedge[100010];
vector<int> to[100010], id[100010];
vector<int> BEGIN[100010], END[100010];
int edgef[100010], edget[100010];
set<int> nowedge;
vector<int> ansanc;
vector<int> ans;
bool ok;
void dfs1(int x) {
  for (int i = 0; i < to[x].size(); i++) {
    int v = to[x][i];
    if (high[v] == -1) high[v] = high[x] + 1, dfs1(v), treeedge[id[x][i]] = 1;
  }
}
void dfs2(int x) {
  for (int i = 0; i < to[x].size(); i++) {
    int v = to[x][i];
    if (high[v] == high[x] + 1) dfs2(v);
  }
  if (nowedge.size() > 1) ok = 0;
  for (int i = 0; i < BEGIN[x].size(); i++) nowedge.erase(BEGIN[x][i]);
  if (ok && BEGIN[x].size()) ansanc.push_back(BEGIN[x][0]);
  if (nowedge.size() == 0) ok = 1;
  for (int i = 0; i < END[x].size(); i++) nowedge.insert(END[x][i]);
}
void dfs3(int ID) {
  ans.push_back(ID);
  int u = edgef[ID], v = edget[ID];
  if (high[u] > high[v]) swap(u, v);
  while (u != v) {
    for (int i = 0; i < to[v].size(); i++) {
      int x = to[v][i];
      if (high[x] == high[v] - 1) {
        ans.push_back(id[v][i]), v = x;
        break;
      }
    }
  }
}
int main() {
  int n, m;
  int u, v;
  cin >> n >> m;
  memset(high, -1, sizeof(high));
  for (int i = 1; i <= m; i++)
    scanf("%d%d", &u, &v), id[u].push_back(i), id[v].push_back(i),
        to[u].push_back(v), to[v].push_back(u), edgef[i] = u, edget[i] = v;
  for (int i = 1; i <= n; i++)
    if (high[i] == -1) high[i] = 0, root[++cnt] = i, dfs1(i);
  ok = 1;
  for (int i = 1; i <= m; i++)
    if (!treeedge[i]) {
      u = edgef[i], v = edget[i];
      if (high[u] > high[v]) swap(u, v);
      BEGIN[u].push_back(i), END[v].push_back(i);
    }
  for (int i = 1; i <= cnt; i++) dfs2(root[i]);
  for (int i = 0; i < ansanc.size(); i++) dfs3(ansanc[i]);
  sort(ans.begin(), ans.end());
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << ' ';
  return 0;
}
