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;
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";
}
