#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef complex P; typedef pair pii; #define REP(i,n) for(ll i=0;i> n >> m; UF uf(n); REP(i,m){ int u,v; cin>>u>>v; --u;--v; uf.unite(u,v); } vl szs; REP(i,n){ if(uf.root(i)==i)szs.push_back(uf.size(i)); } map dp; map::iterator iter; dp[0] = -1; ll t = szs.size(); REP(i,t){ iter = dp.end(); while(iter!=dp.begin()){ --iter; ll id = iter->first; ll val = iter->second; if(id+szs[i]<=n){ if(dp.count(id+szs[i]) == 1) dp[id+szs[i]] = min(dp[id+szs[i]],val+1); else dp[id+szs[i]] = val+1; } } } REPR(i,n+1){ if(dp.count(i) == 1){ cout << dp[i] << endl; }else{ cout << -1 << endl; } } return 0; }