# -*- coding: utf-8 -*- """ No.556 仁義なきサルたち https://yukicoder.me/problems/no/556 """ import sys from sys import stdin input = stdin.readline def solve(monkeys, M): for _ in range(M): a, b = map(int, input().split()) a_boss = monkeys[a][0] b_boss = monkeys[b][0] if a_boss == b_boss: continue if len(monkeys[a_boss][1]) > len(monkeys[b_boss][1]) or (len(monkeys[a_boss][1]) == len(monkeys[b_boss][1]) and a_boss < b_boss): monkeys[b_boss][0] = a_boss monkeys[a_boss][1].append(b_boss) for b in monkeys[b_boss][1]: monkeys[b][0] = a_boss monkeys[a_boss][1].append(b) else: monkeys[a_boss][0] = b_boss monkeys[b_boss][1].append(a_boss) for a in monkeys[a_boss][1]: monkeys[a][0] = b_boss monkeys[b_boss][1].append(a) def main(args): N, M = map(int, input().split()) monkeys = [[x, []] for x in range(N+1)] solve(monkeys, M) for m in monkeys[1:]: print(m[0]) if __name__ == '__main__': main(sys.argv[1:])