# coding: utf-8 N = int(input()) M = int(input()) P_Q = [list(map(int, input().split())) for __ in range(M)] ans = [0] * 3 ans[N - 1] = 1 for p, q in P_Q: ans[p - 1], ans[q - 1] = ans[q - 1], ans[p - 1] print(ans.index(1) + 1)