#include using namespace std; using i64 = int64_t; struct UnionFind { vector par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; return par[x] = root(par[x]); } bool unite(int x, int y) { int rx = root(x), ry = root(y); if (rx == ry) return false; if (size(rx) < size(ry)) swap(rx, ry); par[rx] += par[ry]; par[ry] = rx; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -par[root(x)]; } }; void solve() { int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; uf.unite(a, b); } map C; for (int i = 0; i < n; i++) { if (uf.root(i) == i) { C[uf.size(i)]++; } } vector dp(n + 1, n + 1); dp[0] = 0; for (auto [x, num] : C) { for (int k = 1; num; k <<= 1) { int m = min(k, num); for (int j = n; j >= x; j--) { dp[j] = min(dp[j], dp[j - x] + m); } num -= m; } } for (int i = 1; i <= n; i++) { cout << (dp[i] == n + 1 ? -1 : dp[i] - 1) << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }