n = int(input()) m = int(input()) pq = [list(map(int, input().split())) for _ in range(m)] li = [0] * 4 li[n] = 1 for p, q in pq: li[p], li[q] = li[q], li[p] ans = li.index(1) print(ans)