#include using namespace std; int main() { int N, M; cin >> N >> M; for (int i = 0, p, q; i < M && cin >> p >> q; i++) if (N == p) N = q; cout << N << "\n"; }