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 MAXN = 100005;
int n, m;
struct Edge {
  int u, v;
  int next;
  int ontree;
} E[MAXN * 2];
int header[MAXN], tot = 0;
int vis[MAXN], d[MAXN], dsum[MAXN];
int valpoint[MAXN], link[MAXN];
int ansnum = 0, reverseans[MAXN * 2], ans[MAXN];
int which[MAXN], cnt = 0, root[MAXN];
void addEdge(int u, int v) {
  E[++tot].u = u;
  E[tot].v = v;
  E[tot].ontree = 0;
  E[tot].next = header[u];
  header[u] = tot;
}
void predfs(int x) {
  which[x] = cnt;
  for (int i = header[x]; i; i = E[i].next) {
    int y = E[i].v;
    if (which[y]) continue;
    predfs(y);
  }
}
void dfs(int x) {
  vis[x] = 1;
  for (int i = header[x]; i; i = E[i].next) {
    int y = E[i].v;
    if (vis[y]) continue;
    E[i].ontree = 1;
    if (i & 1)
      E[i + 1].ontree = 1;
    else
      E[i - 1].ontree = 1;
    d[y] = d[x] + 1;
    link[y] = i;
    dfs(y);
  }
}
void dfscount(int x) {
  vis[x] = 1;
  for (int i = header[x]; i; i = E[i].next) {
    int y = E[i].v;
    if (vis[y]) continue;
    dfscount(y);
    valpoint[x] += valpoint[y];
  }
}
void dfssum(int x) {
  vis[x] = 1;
  for (int i = header[x]; i; i = E[i].next) {
    int y = E[i].v;
    if (vis[y]) continue;
    dsum[y] = dsum[x] + valpoint[y];
    dfssum(y);
  }
}
int main() {
  memset(valpoint, 0, sizeof(valpoint));
  memset(d, 0, sizeof(d));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    addEdge(u, v);
    addEdge(v, u);
  }
  for (int i = 1; i <= n; ++i) {
    if (!which[i]) {
      ++cnt;
      predfs(i);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (root[which[i]] == 0) {
      root[which[i]] = i;
    }
  }
  for (int i = 1; i <= cnt; ++i) {
    dfs(root[i]);
  }
  for (int i = 1; i <= 2 * m; i += 2) {
    if (E[i].ontree) continue;
    int tu = E[i].u, tv = E[i].v;
    if (d[tu] < d[tv]) {
      valpoint[tu] -= 1;
      valpoint[tv] += 1;
    } else {
      valpoint[tv] -= 1;
      valpoint[tu] += 1;
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= cnt; ++i) {
    dfscount(root[i]);
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= cnt; ++i) {
    dfssum(root[i]);
  }
  for (int i = 1; i <= 2 * m; i += 2) {
    if (E[i].ontree) continue;
    int tu = E[i].u, tv = E[i].v;
    if (d[tv] < d[tu]) {
      int temp = tv;
      tv = tu;
      tu = temp;
    }
    if (d[tv] - d[tu] == dsum[tv] - dsum[tu]) {
      reverseans[i] = 1;
      reverseans[i + 1] = 1;
      for (int j = tv; j != tu; j = E[link[j]].u) {
        reverseans[link[j]] = 1;
        if (link[j] & 1)
          reverseans[link[j] + 1] = 1;
        else
          reverseans[link[j] - 1] = 1;
      }
    }
  }
  for (int i = 1; i <= 2 * m; i += 2)
    if (reverseans[i] == 1) ans[++ansnum] = i;
  printf("%d\n", ansnum);
  for (int i = 1; i <= ansnum; ++i) {
    printf("%d ", (ans[i] + 1) / 2);
  }
  return 0;
}
