#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from scipy.sparse import csr_matrix from scipy.sparse.csgraph import connected_components import numpy as np N, M = map(int, readline().split()) m = map(int, read().split()) U, V = zip(*zip(m, m)) G = csr_matrix(([1] * M, (U, V)), (N + 1, N + 1)) _, comp = connected_components(G, directed=False) _, counts = np.unique(comp[1:], return_counts=True) counts.sort() size, cnt = np.unique(counts, return_counts=True) INF = 10 ** 6 dp = np.full(N + 1, INF, np.int32) dp[0] = -1 for s, c in zip(size, cnt): cc = 1 while c: c -= cc ss = cc * s np.minimum(dp[ss:], dp[:-ss] + cc, out=dp[ss:]) cc = min(2 * cc, c) dp[dp == INF] = -1 print('\n'.join(dp[1:].astype(str)))