#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x class UF { public: vector par,rank,cnt; UF() {par=rank=vector(um,0); cnt=vector(um,1); for(int i=0;irank[y]) return par[x]=y; rank[x]+=rank[x]==rank[y]; return par[y]=x; } }; UF<500000> uf; map E; int mi[101010],pre[101010]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>M; FOR(i,M) { cin>>x>>y; uf(x-1,y-1); } FOR(i,N) if(uf[i]==i) E[uf.cnt[i]]++; FOR(i,N+1) mi[i]=N+100; mi[0]=0; FORR(r,E) { if(r.first>=100 || r.second<=10) { FOR(j,r.second) { for(i=N-r.first+1;i>=0;i--) mi[i+r.first]=min(mi[i+r.first],mi[i]+1); } } else { set> S[100]; S[0].insert({0,0}); for(i=j=1;i<=N;i++,j++) { pre[i]=mi[i]; if(j>=r.first) j=0; auto it=S[j].begin(); if(it!=S[j].end()) { x=it->first+it->second+(i-it->second)/r.first; mi[i]=min(mi[i],x); } if(pre[i]=0) S[j].erase({pre[x]-(x-j)/r.first,(x-j)/r.first}); } } } for(i=1;i<=N;i++) { if(mi[i]>N) mi[i]=0; _P("%d\n",mi[i]-1); } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }