#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int N = 1e4 + 1, mod = 1e9 + 7;
bool biparite = 1;
int n, m, cnt_biparite = 0, cnt_component = 0, bad_be = 0;
int h[N], dp[N], f[N], color[N];
vector<int> ans, adj[N];
map<pair<int, int>, int> id;
void dfs(int v, bool c) {
  color[v] = c;
  for (auto u : adj[v]) {
    if (color[u] == c) {
      biparite = 0;
    }
    if (h[u] == 0) {
      h[u] = 1;
      dfs(u, 1 - c);
    }
  }
}
void visit(int v, int p) {
  for (auto u : adj[v]) {
    if (u == p) {
      continue;
    }
    if (h[u] == 0) {
      h[u] = h[v] + 1;
      visit(u, v);
      dp[v] += dp[u];
      f[v] += f[u];
    } else {
      if (h[u] < h[v]) {
        if (color[u] == color[v]) {
          bad_be++;
          dp[v]++;
        } else {
          f[v]++;
        }
      } else {
        if (color[u] == color[v]) {
          dp[v]--;
        } else {
          f[v]--;
        }
      }
    }
  }
}
void check(int v, int p) {
  for (auto u : adj[v]) {
    if (u == p) {
      continue;
    }
    if (h[u] == 0) {
      h[u] = h[v] + 1;
      check(u, v);
    } else {
      if (h[u] < h[v]) {
        if (color[u] == color[v]) {
          if (bad_be == 1) {
            ans.push_back(id[{u, v}]);
          }
        }
      }
    }
  }
  if (bad_be && bad_be == dp[v] && f[v] == 0) {
    ans.push_back(id[{v, p}]);
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
    id[{u, v}] = id[{v, u}] = i;
  }
  memset(color, -1, sizeof color);
  int root = 0;
  for (int i = 1; i <= n; ++i) {
    if (h[i]) {
      continue;
    }
    biparite = 1;
    h[i] = 1;
    dfs(i, 1);
    cnt_component++;
    if (biparite) {
      cnt_biparite++;
    } else {
      root = i;
    }
  }
  if (cnt_biparite == cnt_component) {
    cout << m << '\n';
    for (int i = 1; i <= m; ++i) {
      cout << i << ' ';
    }
    return 0;
  }
  if (cnt_component - cnt_biparite > 1) {
    cout << 0;
    return 0;
  }
  memset(h, 0, sizeof h);
  h[root] = 1;
  visit(root, 0);
  memset(h, 0, sizeof h);
  h[root] = 1;
  check(root, 0);
  sort(ans.begin(), ans.end());
  cout << ans.size() << '\n';
  for (auto x : ans) {
    cout << x << ' ';
  }
}
