#include using namespace std; int main() { int N, M; cin >> N >> M; int P, Q; for(int i = 0; i < M; i++) { cin >> P >> Q; if(N == P) N = Q; else if(N == Q) N = P; } cout << N << endl; return 0; }