#include using namespace std; #define int long long signed main(){ int N,Q; cin>>N>>Q; for(int i=0;i>a>>b; if(a == N) N = b; else if(b == N) N = a; } cout<