N,M = map(int,input().split()) parent = [[i,1] for i in range(N+1)] import sys sys.setrecursionlimit(10 ** 8) def find(i): if parent[i][0] == i:return i parent[i][0] = find(parent[i][0]) return parent[i][0] def unite(i,j): I = find(i) J = find(j) if I == J:return False ni = parent[I][1] nj = parent[J][1] if ni < nj: parent[J][1] += parent[I][1] parent[I][0] = J elif ni > nj: parent[I][1] += parent[J][1] parent[J][0] = I else: if I > J: parent[J][1] += parent[I][1] parent[I][0] = J else: parent[I][1] += parent[J][1] parent[J][0] = I return True for _ in range(M): a,b = map(int,input().split()) unite(a,b) for i in range(1,N+1): print(find(i))