def get_root(monkey_data, monkey_id): for monkey_root in monkey_data: if monkey_id in monkey_data[monkey_root]: return monkey_root if __name__ == "__main__": n, m = map(int, input().split(" ")) root_data = {i + 1: (i + 1,) for i in range(n)} for i in range(m): a, b = map(int, input().split(" ")) a_root = get_root(root_data, a) b_root = get_root(root_data, b) if a_root != b_root: if len(root_data[a_root]) != len(root_data[b_root]): if len(root_data[a_root]) < len(root_data[b_root]): root_data.update({b_root: root_data[b_root] + root_data.pop(a_root)}) else: root_data.update({a_root: root_data[a_root] + root_data.pop(b_root)}) else: if a_root < b_root: root_data.update({a_root: root_data[a_root] + root_data.pop(b_root)}) else: root_data.update({b_root: root_data[b_root] + root_data.pop(a_root)}) monkey_root_list = [0 for i in range(n)] for monkey_key in root_data: for monkey_num in root_data[monkey_key]: monkey_root_list[monkey_num - 1] = monkey_key print(*monkey_root_list, sep="\n")