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;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
clock_t start = clock();
long long int gcd(long long int a, long long int b) {
  return (a == 0) ? b : gcd(b % a, a);
}
long long int power(long long int a, long long int n) {
  long long int p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long int powm(long long int a, long long int n, long long int mod_) {
  long long int p = 1;
  while (n) {
    if (n % 2) {
      p = (((p % mod_) * 1LL * (a % mod_)) % mod_);
    }
    n >>= 1;
    a = (((a % mod_) * 1LL * (a % mod_)) % mod_);
  }
  return p % mod_;
}
long long int powi(long long int a, long long int mod_) {
  return powm(a, mod_ - 2, mod_);
}
vector<set<int>> g;
vector<long long int> col, dp, par, art;
map<pair<long long int, long long int>, long long int> ed;
vector<long long int> ans;
void dfs(long long int x) {
  col[x] = 1;
  for (auto y : g[x]) {
    if (col[y] == 1 and y != par[x]) {
      dp[y]--;
      dp[x]++;
      art[y]--;
      if (par[x] != -1) art[par[x]]++;
    } else if (col[y] == 0) {
      par[y] = x;
      dfs(y);
      dp[x] += dp[y];
      art[x] += art[y];
    }
  }
  col[x] = 2;
}
bool ok = true;
void dfs2(long long int x) {
  col[x] = 1;
  for (auto y : g[x]) {
    if (col[y] == 1 and y != par[x]) {
      dp[y]--;
      dp[x]++;
      ans.push_back(ed[{x, y}]);
    } else if (col[y] == 0) {
      ans.push_back(ed[{x, y}]);
      par[y] = x;
      dfs2(y);
      dp[x] += dp[y];
    }
  }
  col[x] = 2;
  if (par[x] != -1 and dp[x] != 1) {
    ;
    ok = false;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int mn, mx;
  long long int n, m, k, t, i, j, sum = 0, flag = 0, cnt = 0;
  long long int x = 0, y = 0, z, l = 0, r = 0, q;
  int TC = 1;
  while (TC--) {
    cin >> n >> m;
    g.assign(n, {});
    col.assign(n, 0);
    dp.assign(n, 0);
    art.assign(n, 0);
    par.assign(n, -1);
    for (i = 0; i < m; ++i) {
      cin >> x >> y;
      --x;
      --y;
      ed[{x, y}] = i + 1;
      ed[{y, x}] = i + 1;
      g[x].insert(y);
      g[y].insert(x);
    };
    for (i = 0; i < n; ++i) {
      if (!col[i]) dfs(i);
    };
    for (i = 0; i < n; ++i) {
      if (par[i] != -1 and dp[i] == 0) {
        g[i].erase(par[i]);
        g[par[i]].erase(i);
      }
    };
    vector<long long int> res;
    fill((col).begin(), (col).end(), 0);
    fill((dp).begin(), (dp).end(), 0);
    fill((par).begin(), (par).end(), -1);
    for (i = 0; i < n; ++i) {
      if (col[i] == 0) {
        ans.clear();
        ok = true;
        dfs2(i);
        if (ok) {
          for (auto x : ans) res.push_back(x);
        }
      }
    };
    sort((res).begin(), (res).end());
    cout << (long long int)((res).size()) << '\n';
    for (auto x : res) cout << x << ' ';
  };
  return 0;
}
