#include int main(){ int cup, N, i; int P, Q; scanf("%d %d\n", &cup, &N); for(i = 0; i < N; i++){ scanf("%d %d\n", &P, &Q); if(cup == P){ cup = Q; }else if(cup == Q){ cup = P; } } printf("%d\n", cup); return 0; }