#coding:utf-8 N=input() M=input() ope=[raw_input().split() for i in range(M)] for p,q in ope: if int(p)==N: N=int(q) elif int(q)==N: N=int(p) print N