#include"bits/stdc++.h" using namespace std; int main() { int N, M; cin >> N >> M; vector P(M), Q(M); for(int i=0; i> P[i] >> Q[i]; for (int i = 0; i < M; i++) { if (P[i] == N) { N = Q[i]; } else if (Q[i] == N) { N = P[i]; } } cout << N << endl; }