class DisjointSet556(object): def __init__(self, n): self.parent = list(range(n)) self.rank = [1] * n def union(self, x, y): self._link(self.find_set(x), self.find_set(y)) def _link(self, x, y): if x == y: return if self.rank[x] > self.rank[y]: self.parent[y] = x self.rank[x] += self.rank[y] elif self.rank[x] < self.rank[y]: self.parent[x] = y self.rank[y] += self.rank[x] elif x < y: self.parent[y] = x self.rank[x] += self.rank[y] else: self.parent[x] = y self.rank[y] += self.rank[y] def find_set(self, x): xp = self.parent[x] if xp != x: self.parent[x] = self.find_set(xp) return self.parent[x] N, M = map(int, input().split()) ds = DisjointSet556(N) for m in range(M): a, b = map(int, input().split()) ds.union(a - 1, b - 1) for i in range(N): print(ds.find_set(i) + 1)