n = int(input()) m = int(input()) ret = n for _ in range(m): p,q = map(int,input().split()) if ret==p: ret = q if ret==q: ret = p print(ret)