# -*- coding: utf-8 -*- n = int(input()) m = int(input()) p = [0] * m q = [0] * m for i in range(m): p[i], q[i] = map(int,input().split()) for i in range(m): if p[i] == n: n = q[i] elif q[i] == n: n = p[i] print(n)