#include using namespace std; #define REP(i,a,b) for(i=a;i'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(unsigned *x){int k;*x=0;for(;;){mygc(k);if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}} void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);} void reader(double *x){scanf("%lf",x);} int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;} template void reader(T *x, S *y){reader(x);reader(y);} template void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);} template void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);} void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(unsigned x, char c){int s=0;char f[10];while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;while(s--)mypc(f[s]+'0');mypc(c);} void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);} void writer(double x, char c){printf("%.15f",x);mypc(c);} void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);} void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);} template void writerLn(T x){writer(x,'\n');} template void writerLn(T x, S y){writer(x,' ');writer(y,'\n');} template void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');} template void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');} void reader_u(int &x, char c){int k;x=0;for(;;){mygc(k);if(k==c)break;x=x*10+k-'0';}} void writer_u(int x, char c){int s=0;char f[10];while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;while(s--)mypc(f[s]+'0');mypc(c);} char memarr[17000000]; void *mem = memarr; #define INF 1000000000 template void sort(int N, T a[], void *mem = NULL){sort(a,a+N);} template void sort(int N, T1 a[], T2 b[], void *mem){int i;pair *r=(pair*)mem;rep(i,N)r[i].first=a[i],r[i].second=b[i];sort(r,r+N);rep(i,N)a[i]=r[i].first,b[i]=r[i].second;} template void sort(int N, T1 a[], T2 b[], T3 c[], void *mem){int i;pair > *r=(pair >*)mem;rep(i,N)r[i].first=a[i],r[i].second.first=b[i],r[i].second.second=c[i];sort(r,r+N);rep(i,N)a[i]=r[i].first,b[i]=r[i].second.first,c[i]=r[i].second.second;} template void sort(int N, T1 a[], T2 b[], T3 c[], T4 d[], void *mem){int i;pair,pair > *r=(pair,pair >*)mem;rep(i,N)r[i].first.first=a[i],r[i].first.second=b[i],r[i].second.first=c[i],r[i].second.second=d[i];sort(r,r+N);rep(i,N)a[i]=r[i].first.first,b[i]=r[i].first.second,c[i]=r[i].second.first,d[i]=r[i].second.second;} struct unionFind{ int *d, N, M; inline void malloc(int n){ d = (int*)std::malloc(n*sizeof(int)); M = n; } inline void *malloc(int n, void *mem){ d = (int*)mem; M = n; return d + n; } inline void init(int n){ int i; N = n; rep(i,n) d[i] = -1; } inline void init(void){ init(M); } inline int get(int a){ int t = a, k; while(d[t]>=0) t=d[t]; while(d[a]>=0) k=d[a], d[a]=t, a=k; return a; } inline int connect(int a, int b){ if(d[a]>=0) a=get(a); if(d[b]>=0) b=get(b); if(a==b) return 0; if(d[a] < d[b]) d[a] += d[b], d[b] = a; else d[b] += d[a], d[a] = b; return 1; } inline int operator()(int a){ return get(a); } inline int operator()(int a, int b){ return connect(a,b); } inline int& operator[](int a){ return d[a]; } inline int sizeList(int res[]){ int i, sz=0; rep(i,N) if(d[i]<0) res[sz++] = -d[i]; return sz; } }; template inline void chmin(S &a, T b){if(a>b)a=b;} template inline void chmax(S &a, T b){if(a=g;i--) chmin(dp[i], dp[i-g]+c); } else { unsigned cc[4] = {c,c,c,c}; for(i=st;i-3>=g;i-=4){ SSE4_M128U_MINADD32(dp[i-3], dp[i-3], dp[i-g-3], cc[0]); } for(;i>=g;i--) chmin(dp[i], dp[i-g]+c); } } int qs, qcost[100001], qgain[100001]; int main(){ int i, j, k, st; unionFind uf; reader_u(N,' '); reader_u(M,'\n'); mem = uf.malloc(N, mem); uf.init(N); while(M--){ reader_u(i,' '); reader_u(j,'\n'); uf(i-1, j-1); } rep(i,N) if(uf[i]<0) gain[-uf[i]]++; st = 0; REP(i,1,N+1) dp[i] = INF; REP(k,1,N+1) while(gain[k]){ i = (gain[k]+1) / 2; qcost[qs] = i; qgain[qs++] = k*i; gain[k] -= i; } sort(qs, qgain, qcost, mem); rep(i,qs) update(qgain[i], qcost[i], st+=qgain[i]); REP(i,1,N+1){ if(dp[i]==INF) mypc('-'), mypc('1'), mypc('\n'); else writer_u(dp[i]-1,'\n'); } return 0; }