# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) M = int(input()) X = [0]*3 X[N-1] = 1 for _ in range(M): p,q = map(int,input().split()) p -= 1 q -= 1 X[p],X[q] = X[q],X[p] for i in range(3): if X[i]==1: print(i+1) exit()