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