from collections import defaultdict N,M = map(int,raw_input().split()) parent = range(N) conn_comp = defaultdict(int) def root(x): while x != parent[x]: parent[x] = x = parent[parent[x]] return x for i in xrange(M): u,v = map(lambda x:root(int(x)-1),raw_input().split()) parent[u] = v for i in xrange(N): conn_comp[root(i)] += 1 vertex_num = conn_comp.values() vertex_num.sort(reverse=True) prev = range(-1,N+1) ans = [-1 for i in xrange(N+1)] tmp_max = 0 for n in vertex_num: dec = tmp_max = tmp_max + n r = [] while dec > n: if ans[dec] == -1: if ans[dec-n] != -1: ans[dec] = ans[dec-n] + 1 r.append(dec+1) else: for i in r: prev[i] = dec r = [] dec = prev[dec] ans[n] = 0 for i in xrange(N): print ans[i+1]