n = int(input()) m = int(input()) array = [list(map(int,input().split())) for i in range(m)] before = n for i,j in array: if i==before: before=j elif j==before: before=i print(before)