#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000 + 10;
bool col[MAXN];
int n, e, cnt, Time;
int vis[MAXN], type[MAXN], start[MAXN], finish[MAXN], ER[MAXN], NER[MAXN];
int pr[MAXN][25];
struct edge {
  int first, second;
  edge() { first = second = 0; }
  edge(int f, int s) {
    first = f;
    second = s;
  }
} par[MAXN];
vector<edge> adj[MAXN];
void dfs(int v, int id, bool c) {
  if (par[v].first == 0)
    pr[v][0] = v;
  else
    pr[v][0] = par[v].first;
  for (int i = 1; i <= 20; i++) pr[v][i] = pr[pr[v][i - 1]][i - 1];
  start[v] = Time;
  Time++;
  vis[v] = id;
  col[v] = c;
  for (int i = 0; i < adj[v].size(); i++)
    if (vis[adj[v][i].first] == 0) {
      par[adj[v][i].first] = edge(v, adj[v][i].second);
      dfs(adj[v][i].first, id, !c);
    }
  finish[v] = Time;
  Time++;
}
bool checkPar(int P, int v) {
  return start[P] <= start[v] && finish[P] >= finish[v];
}
int lca(int a, int b, int pw) {
  if (checkPar(b, a)) return b;
  if (checkPar(a, b)) return a;
  while (pw >= 0 && checkPar(pr[a][pw], b)) pw--;
  return (pw == -1) ? pr[a][0] : lca(pr[a][pw], b, pw);
}
void DFS(int v) {
  for (int i = 0; i < adj[v].size(); i++)
    if (pr[adj[v][i].first][0] == v) {
      DFS(adj[v][i].first);
      ER[v] += ER[adj[v][i].first];
      NER[v] += NER[adj[v][i].first];
    }
}
int main() {
  scanf("%d%d", &n, &e);
  for (int i = 1; i <= e; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(edge(b, i));
    adj[b].push_back(edge(a, i));
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] == 0) {
      cnt++;
      dfs(i, cnt, 0);
    }
  int error = 0;
  set<int> T;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < adj[i].size(); j++) {
      int a = i, b = adj[i][j].first, c = adj[i][j].second;
      if (a > b) continue;
      if (pr[a][0] == b || pr[b][0] == a)
        type[c] = 1;
      else if (col[a] == col[b]) {
        type[c] = 2;
        error++;
        T.insert(vis[a]);
      } else
        type[c] = 3;
    }
  if (error == 0) {
    printf("%d\n", e);
    for (int i = 1; i <= e; i++) printf("%d ", i);
    printf("\n");
    return 0;
  }
  if (T.size() > 1u) {
    puts("0");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    if (vis[i] == *T.begin())
      for (int j = 0; j < adj[i].size(); j++)
        if (i < (adj[i][j].first)) {
          if (type[adj[i][j].second] == 2) {
            ER[i]++;
            ER[adj[i][j].first]++;
            ER[lca(i, adj[i][j].first, 20)] -= 2;
          }
          if (type[adj[i][j].second] == 3) {
            NER[i]++;
            NER[adj[i][j].first]++;
            NER[lca(i, adj[i][j].first, 20)] -= 2;
          }
        }
  for (int i = 1; i <= n; i++)
    if (vis[i] == *T.begin()) {
      DFS(i);
      break;
    }
  vector<int> ans;
  for (int i = 1; i <= n; i++)
    if (ER[i] == error && NER[i] == 0) ans.push_back(par[i].second);
  if (error == 1) {
    for (int i = 1; i <= e; i++)
      if (type[i] == 2) ans.push_back(i);
  }
  sort(ans.begin(), ans.end());
  printf("%u\n", ans.size());
  for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
