import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n = int(readline()) m = int(readline()) pq = [list(map(int, readline().split())) for i in range(m)] ans = [0, 0, 0, 0] ans[n] = 1 for p, q in pq: ans[p], ans[q] = ans[q], ans[p] for i in range(4): if ans[i] == 1: print(i)