#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef long long LL; typedef vector VLL; typedef unsigned long long ULL; typedef pair PIL; typedef vector VPIL; //#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) //#define sort(c) sort((c).begin(),(c).end()) #define range(i,a,b) for(int i=(a); i < (b); i++) #define rep(i,n) range(i,0,n) int parent[100001]; int root(int x){ if (x != parent[x]) parent[x] = root(parent[x]); return parent[x]; } int main(){ int N,M,C,u,v,c,w; map conn_comp, comp_num; map :: iterator mit; VI ans; cin >> N >> M; ans = VI(N+1,N); ans[0] = 0; rep(i,N) parent[i] = i; rep(i,M){ cin >> u >> v; u = root(u-1); v = root(v-1); if (u!=v) parent[u] = v; } rep(i,N) conn_comp[root(i)]++; for (mit=conn_comp.begin();mit!=conn_comp.end();mit++) comp_num[mit->second]++; for (mit=comp_num.begin();mit!=comp_num.end();mit++){ c = 1; w = mit->first; C = mit->second; while (c <= C){ if ((c&C) != 0) for (int i = N; i >= w; i--) ans[i] = min(ans[i],ans[i-w]+c); c *= 2; w *= 2; } } rep(i,N) cout << (ans[i+1]==N ? -1 : ans[i+1]-1) << endl; return 0; }