#include #define REP(x,y,z) for(int x=y;x<=z;x++) #define FORD(x,y,z) for(int x=y;x>=z;x--) #define MSET(x,y) memset(x,y,sizeof(x)) #define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++) #define F first #define S second #define MP make_pair #define PB push_back #define SZ size() #define M 100005 #define INF 1000000000 void RI(){} template void RI( int& head, T&... tail ) { scanf("%d",&head); RI(tail...); } using namespace std; typedef long long LL; int n,m,fa[M],w[M],cnt[M],dp[M]; int find(int x) { return fa[x]==x ? x:fa[x]=find(fa[x]); } void con(int x,int y) { x=find(x); y=find(y); if(x==y) return; fa[x] = y; w[y] += w[x]; } void upd(int x,int y) { printf("%d %d\n",x,y); FORD(i,n,x) dp[i]=min(dp[i], dp[i-x]+y); } int main() { int x,y; while(~scanf("%d %d",&n,&m)) { dp[0]=0; REP(i,1,n) fa[i]=i, w[i]=1, cnt[i]=0, dp[i]=INF; REP(i,1,m) { RI(x,y); con(x,y); } REP(i,1,n) if(find(i)==i) cnt[w[i]]++; REP(i,1,n) if(cnt[i]) { x = cnt[i]; y = 1; while(x>=y) { upd(i*y, y); x-=y; y*=2; } if(x) upd(i*x, x); } REP(i,1,n) printf("%d\n",dp[i]==INF?-1:dp[i]-1); } return 0; }