#include using namespace std; int main(void){ int n,i,a,b; cin>>i>>n; for(;n--;){ cin>>a>>b; if(a==i) i=b; else if(b==i) i=a; } cout<