#include using namespace std; int main(void){ int N, M, p, q; cin >> N >> M; while(M--){ cin >> p >> q; if(N == p) N = q; } cout << N << endl; return 0; }