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 INFINITE = INT_MAX;
template <typename T>
struct SegTree {
  struct SegTreeNode {
    T val;
    T addMark;
  };
  vector<SegTreeNode> nodes;
  T *arr;
  int istart, iend, maxIndex;
  SegTree() {}
  SegTree(T *arr1, int start, int end) : arr(arr1), istart(start), iend(end) {
    nodes.resize((end - start + 1) << 2);
    maxIndex = -1;
    build(0, arr, istart, iend);
  }
  void build(int root, T arr[], int istart, int iend) {
    nodes[root].addMark = 0;
    if (istart == iend) {
      if (root > maxIndex) maxIndex = root;
      nodes[root].val = arr[istart];
    } else {
      int mid = (istart + iend) / 2;
      build(root * 2 + 1, arr, istart, mid);
      build(root * 2 + 2, arr, mid + 1, iend);
      nodes[root].val = min(nodes[root * 2 + 1].val, nodes[root * 2 + 2].val);
    }
  }
  void pushDown(int root) {
    if (nodes[root].addMark != 0) {
      nodes[root].val += nodes[root].addMark;
      if ((root << 1) + 1 <= maxIndex)
        nodes[(root << 1) + 1].addMark += nodes[root].addMark;
      if ((root << 1) + 2 <= maxIndex)
        nodes[(root << 1) + 2].addMark += nodes[root].addMark;
      nodes[root].addMark = 0;
    }
  }
  T query(int qstart, int qend) { return query(0, istart, iend, qstart, qend); }
  T query(int root, int nstart, int nend, int qstart, int qend) {
    if (qstart > nend || qend < nstart) return INFINITE;
    if (qstart <= nstart && qend >= nend) {
      pushDown(root);
      return nodes[root].val;
    }
    pushDown(root);
    int mid = (nstart + nend) / 2;
    return min(query(root * 2 + 1, nstart, mid, qstart, qend),
               query(root * 2 + 2, mid + 1, nend, qstart, qend));
  }
  void update(int ustart, int uend, T addValue) {
    update(0, istart, iend, ustart, uend, addValue);
  }
  void update(int root, int nstart, int nend, int ustart, int uend, T addVal) {
    if (ustart > nend || uend < nstart) return;
    if (ustart <= nstart && uend >= nend) {
      nodes[root].addMark += addVal;
      pushDown(root);
      return;
    }
    pushDown(root);
    int mid = (nstart + nend) / 2;
    update(root * 2 + 1, nstart, mid, ustart, uend, addVal);
    update(root * 2 + 2, mid + 1, nend, ustart, uend, addVal);
    nodes[root].val = min(nodes[root * 2 + 1].val, nodes[root * 2 + 2].val);
  }
  void updateOne(int index, T addVal) {
    updateOne(0, istart, iend, index, addVal);
  }
  void updateOne(int root, int nstart, int nend, int index, T addVal) {
    if (nstart == nend) {
      if (index == nstart) {
        pushDown(root);
        nodes[root].val += addVal;
      }
      return;
    }
    int mid = (nstart + nend) / 2;
    pushDown(root);
    if (index <= mid)
      updateOne(root * 2 + 1, nstart, mid, index, addVal);
    else
      updateOne(root * 2 + 2, mid + 1, nend, index, addVal);
    nodes[root].val = min(nodes[root * 2 + 1].val, nodes[root * 2 + 2].val);
  }
};
const int V = 1e5 + 20;
struct node {
  int v;
  int idx;
  bool flag;
  node(int a = 0, int b = 0, bool c = 0) : v(a), idx(b), flag(c) {}
};
vector<node> adj[V];
int parent[V], heavy[V];
int depth[V], size[V];
int chain[V], head[V], pos[V];
int vist[V];
vector<int> realChain[V];
SegTree<int> trees[V];
int ids[V];
vector<pair<int, int> > nonEds;
int n, m;
void DFS(int i) {
  size[i] = 1, vist[i] = 1;
  for (int k = 0; k < adj[i].size(); ++k) {
    auto &ele = adj[i][k];
    int j = ele.v;
    if (j == parent[i]) {
      ele.flag = 1;
      continue;
    }
    if (vist[j] == 1) {
      ele.flag = 0;
      continue;
    }
    ele.flag = 1;
    parent[j] = i;
    ids[j] = ele.idx;
    depth[j] = depth[i] + 1;
    DFS(j);
    size[i] += size[j];
    if (heavy[i] == -1 || size[j] > size[heavy[i]]) heavy[i] = j;
  }
}
void heavylight_DFS(int N) {
  memset(heavy, -1, sizeof(heavy));
  memset(vist, 0, sizeof(vist));
  for (int i = 1; i <= N; i++) {
    if (!vist[i]) {
      parent[i] = -1;
      depth[i] = 0;
      DFS(i);
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < adj[i].size(); j++) {
      int u = adj[i][j].v;
      if (i < u && adj[i][j].flag == 0) {
        nonEds.push_back({i, j});
      }
    }
  }
  int c = 0;
  for (int i = 1; i <= N; ++i)
    if (parent[i] == -1 || heavy[parent[i]] != i) {
      for (int k = i, p = 0; k != -1; k = heavy[k]) {
        chain[k] = c, head[k] = i, pos[k] = p++;
        realChain[c].push_back(0);
      }
      c++;
    }
  for (int i = 0; i < c; i++) {
    trees[i] =
        SegTree<int>(realChain[i].data(), 0, (int)realChain[i].size() - 1);
  }
}
int query(int i, int j) {
  int ans = INT_MIN;
  int cid, pp, pp2;
  while (chain[i] != chain[j]) {
    if (depth[head[i]] > depth[head[j]]) swap(i, j);
    cid = chain[j], pp = pos[j];
    ans = max(ans, trees[cid].query(0, pp));
    j = parent[head[j]];
  }
  cid = chain[i], pp = pos[i], pp2 = pos[j];
  if (pp > pp2) swap(pp, pp2);
  if (pp == pp2)
    return ans;
  else {
    pp++;
    ans = max(ans, trees[cid].query(pp, pp2));
    return ans;
  }
}
void update(int i, int j) {
  int cid, pp, pp2;
  while (chain[i] != chain[j]) {
    if (depth[head[i]] > depth[head[j]]) swap(i, j);
    cid = chain[j], pp = pos[j];
    trees[cid].update(0, pp, 1);
    j = parent[head[j]];
  }
  cid = chain[i], pp = pos[i], pp2 = pos[j];
  if (pp > pp2) swap(pp, pp2);
  if (pp != pp2) {
    pp++;
    trees[cid].update(pp, pp2, 1);
  }
}
vector<int> bb;
void allo(int v, int u) {
  while (v != u) {
    if (depth[v] > depth[u]) {
      bb.push_back(ids[v]);
      v = parent[v];
    } else {
      bb.push_back(ids[u]);
      u = parent[u];
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back({b, i + 1, 0});
    adj[b].push_back({a, i + 1, 0});
  }
  heavylight_DFS(n);
  for (int i = 0; i < nonEds.size(); i++) {
    int v = nonEds[i].first, u = adj[v][nonEds[i].second].v;
    update(v, u);
  }
  int ans = 0;
  for (int i = 0; i < nonEds.size(); i++) {
    int v = nonEds[i].first, u = adj[v][nonEds[i].second].v;
    int aa = query(v, u);
    if (aa == 1) {
      allo(v, u);
      bb.push_back(adj[v][nonEds[i].second].idx);
      ans += abs(depth[v] - depth[u]) + 1;
    }
  }
  printf("%d\n", ans);
  assert(ans == bb.size());
  for (int i = 0; i < bb.size(); i++) printf("%d ", bb[i]);
  printf("\n");
  return 0;
}
