#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, m, u, v; cin >> n >> m; atcoder::dsu uf(n); while(m--){ cin >> u >> v; uf.merge(--u, --v); } auto G = uf.groups(); vector b; vector> a; b.reserve(G.size()); a.reserve(G.size()); for(auto &&vec : G) b.emplace_back(vec.size()); sort(b.begin(), b.end()); for(int i = 0; i < b.size(); ){ int p = i; while(i < b.size() && b[i] == b[p]) i++; int v = i - p; for(int j = 0; v; j++){ if(v >= (1 << j)){ v -= 1 << j; a.emplace_back(b[p] * (1 << j), 1 << j); }else{ a.emplace_back(b[p] * v, v); v = 0; } } } sort(a.begin(), a.end()); vector dp(n + 1, 1 << 30); dp[0] = 0; for(int i = 0, s = 0; i < a.size(); i++){ int v, c; tie(v, c) = a[i]; for(int j = s; j >= 1; j--){ dp[j + v] = min(dp[j + v], dp[j] + c); } dp[v] = min(dp[v], c - 1); s += v; } for(int i = 1; i <= n; i++) cout << (dp[i] >> 30 ? -1 : dp[i]) << '\n'; }