#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% N, M = map(int, readline().split()) m = map(int, read().split()) AB = zip(m, m) # %% class UnionFind: def __init__(self, N): self.root = list(range(N)) self.size = [1] * (N) def find_root(self, x): root = self.root while root[x] != x: root[x] = root[root[x]] x = root[x] return x def merge(self, x, y): x = self.find_root(x) y = self.find_root(y) if x == y: return False if x > y: x, y = y, x sx, sy = self.size[x], self.size[y] if sx < sy: self.root[x] = y self.size[y] += sx else: self.root[y] = x self.size[x] += sy return True # %% uf = UnionFind(N + 1) for a, b in AB: uf.merge(a, b) # %% boss = (uf.find_root(x) for x in range(1, N + 1)) print('\n'.join(map(str, boss)))