N = int(input()) M = int(input()) cups = [False,False,False,False] cups[N] = True for _ in range(M): P,Q = map(int,input().split()) if cups[P]: cups[Q] = True cups[P] = False elif cups[Q]: cups[P] = True cups[Q] = False for idx,item in enumerate(cups): if item: print(idx) break