N,M=map(int,input().split()) from collections import Counter # UnionFind Group = [i for i in range(N)] # グループ分け Nodes = [1]*(N) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for i in range(M): x,y=map(int,input().split()) x-=1 y-=1 Union(x,y) LIST=[] for i in range(N): if find(i)==i: LIST.append(Nodes[i]) C=Counter(LIST) DP=[1<<30]*(N+1) DP[0]=0 for l in LIST: c=C[l] LL=[] for j in range(30): if c>2**i: LL.append(2**i) c-=2**i else: LL.append(c) break #print(DP,LL) for x in LL: for j in range(N-x*l,-1,-1): if DP[j]!=1<<30: DP[j+x*l]=min(DP[j+x*l],DP[j]+x) #print(DP) for i in range(1,N+1): if DP[i]==1<<30: print(-1) else: print(DP[i]-1)