n, m = [int(x) for x in input().strip().split()] boss = [x for x in range(n+1)] piki = [1 for _ in range(n+1)] for _ in range(m): a, b = [int(x) for x in input().strip().split()] if boss[a] == boss[b]: pass else: ta = boss[a] tb = boss[b] if piki[ta] > piki[tb] or (piki[ta] == piki[tb] and ta < tb): piki[ta] += piki[tb] for i in range(n+1): if boss[i] == tb: boss[i] = ta else: piki[tb] += piki[ta] for i in range(n+1): if boss[i] == ta: boss[i] = tb for x in boss[1:]: print(x)