#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double Pi = 3.1415926535897932;
const int dir[4][2] = {-1, 0, 0, -1, 1, 0, 0, 1};
const int maxn = 1e4 + 5;
struct EDGE {
  int a, b;
  int A, B;
} edge[maxn];
int n, m;
int last[maxn];
vector<int> G[maxn], tree[maxn];
int d[maxn];
int A[maxn], B[maxn];
bool vis[maxn];
vector<int> ans;
int in[maxn];
void dfs_tree(int a, int fa) {
  vis[a] = true;
  for (int i = 0; i < G[a].size(); i++) {
    int p = G[a][i];
    if (p == last[a]) continue;
    int b = edge[p].a ^ edge[p].b ^ a;
    if (!vis[b]) {
      tree[a].push_back(p);
      in[p] = true;
      d[b] = d[a] + 1;
      last[b] = p;
      dfs_tree(b, a);
    } else if (d[a] > d[b]) {
      if (d[a] - d[b] + 1 & 1) {
        ans.push_back(p);
        B[a]++;
        B[b]--;
      } else {
        A[a]++;
        A[b]--;
      }
    }
  }
}
void dfs(int a) {
  vis[a] = true;
  for (int i = 0; i < tree[a].size(); i++) {
    int p = tree[a][i];
    int b = edge[p].a ^ edge[p].b ^ a;
    if (!vis[b]) dfs(b);
    A[a] += A[b];
    B[a] += B[b];
  }
  edge[last[a]].A = A[a];
  edge[last[a]].B = B[a];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    edge[i] = EDGE{a, b};
    G[a].push_back(i);
    G[b].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs_tree(i, -1);
  }
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  if (ans.size() == 0) {
    for (int i = 1; i <= m; i++) ans.push_back(i);
  } else if (ans.size() == 1) {
    for (int i = 1; i <= m; i++)
      if (in[i]) {
        if (edge[i].A == 0 && edge[i].B) ans.push_back(i);
      }
  } else {
    int t = ans.size();
    ans.clear();
    for (int i = 1; i <= m; i++)
      if (in[i]) {
        if (edge[i].B) {
          if (edge[i].B == t && edge[i].A == 0) ans.push_back(i);
        }
      }
  }
  sort(ans.begin(), ans.end());
  printf("%d\n", ans.size());
  for (int i = 0; i < ans.size(); i++)
    printf("%d", ans[i]), putchar(i == ans.size() - 1 ? '\n' : ' ');
  return 0;
}
