n = int(input()) m = int(input()) first = [] second = [] swaplist = [] for i in range(m): first, second = [int(i) for i in input().split()] curlist = [first, second] swaplist.append(curlist) cup = [0] * 3 cup[n-1] = 1 for i in range(m): buf = cup[swaplist[i][1]-1] cup[swaplist[i][1]-1] = cup[swaplist[i][0]-1] cup[swaplist[i][0]-1] = buf res = cup.index(1) + 1 print(res)