class UnionFind: def __init__(self, n): self.par = [-1]*n self.rank = [0]*n def Find(self, x): if self.par[x] < 0: return x else: self.par[x] = self.Find(self.par[x]) return self.par[x] def Unite(self, x, y): x = self.Find(x) y = self.Find(y) if x != y: if self.rank[x] < self.rank[y]: self.par[y] += self.par[x] self.par[x] = y else: self.par[x] += self.par[y] self.par[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 def Same(self, x, y): return self.Find(x) == self.Find(y) def Size(self, x): return -self.par[self.Find(x)] import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n, m = map(int, input().split()) BOSS = list(range(n)) uf = UnionFind(n) for i in range(m): a, b = map(int, input().split()) a, b = a-1, b-1 if uf.Same(a, b): continue if uf.Size(a) > uf.Size(b): boss = BOSS[uf.Find(a)] uf.Unite(a, b) BOSS[uf.Find(a)] = boss elif uf.Size(a) < uf.Size(b): boss = BOSS[uf.Find(b)] uf.Unite(a, b) BOSS[uf.Find(b)] = boss else: if BOSS[uf.Find(a)] < BOSS[uf.Find(b)]: boss = BOSS[uf.Find(a)] uf.Unite(a, b) BOSS[uf.Find(a)] = boss else: boss = BOSS[uf.Find(b)] uf.Unite(a, b) BOSS[uf.Find(b)] = boss for i in range(n): boss = BOSS[uf.Find(i)] print(boss+1)