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 a[100005], b[100005];
vector<int> adj[100005];
int pos = 1, sccPos = 1;
int dfsOrder[100005];
int scc[100005];
stack<int> st;
int dfs(int node, int prevEdge) {
  int ret = dfsOrder[node] = pos++;
  st.push(node);
  for (int edge : adj[node]) {
    if (edge == prevEdge) {
      continue;
    }
    int ch = a[edge] ^ b[edge] ^ node;
    if (dfsOrder[ch] == 0) {
      ret = min(ret, dfs(ch, edge));
    } else if (scc[ch] == 0) {
      ret = min(ret, dfsOrder[ch]);
    }
  }
  if (ret == dfsOrder[node]) {
    while (true) {
      int cur = st.top();
      st.pop();
      scc[cur] = sccPos;
      if (cur == node) {
        break;
      }
    }
    ++sccPos;
  }
  return ret;
}
bool vis[100005];
bool dfs2(int node, int prevEdge) {
  if (vis[node]) {
    return true;
  }
  vis[node] = true;
  for (int edge : adj[node]) {
    if (edge == prevEdge) {
      continue;
    }
    int ch = a[edge] ^ b[edge] ^ node;
    if (dfs2(ch, edge)) {
      return true;
    }
  }
  return false;
}
vector<int> edgeList[100005];
void solve() {
  int n, m;
  scanf("%d %d ", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d ", &a[i], &b[i]);
    adj[a[i]].push_back(i);
    adj[b[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    if (dfsOrder[i] == 0) {
      dfs(i, -1);
    }
  }
  for (int i = 1; i <= n; ++i) {
    adj[i].clear();
  }
  for (int i = 1; i <= m; ++i) {
    if (scc[a[i]] == scc[b[i]]) {
      edgeList[scc[a[i]]].push_back(i);
    }
  }
  vector<int> ret;
  for (int i = 1; i < pos; ++i) {
    if (edgeList[i].size() == 0) {
      continue;
    }
    int node = -1;
    for (int j = 1; j < edgeList[i].size(); ++j) {
      int id = edgeList[i][j];
      adj[a[id]].push_back(id);
      adj[b[id]].push_back(id);
      node = a[id];
    }
    assert(node != -1);
    if (!dfs2(node, -1)) {
      for (int id : edgeList[i]) {
        ret.push_back(id);
      }
    }
    for (int id : edgeList[i]) {
      adj[a[id]].clear();
      adj[b[id]].clear();
    }
  }
  sort(ret.begin(), ret.end());
  printf("%d\n", (int)ret.size());
  for (int id : ret) {
    printf("%d ", id);
  }
}
int main() {
  solve();
  return 0;
}
