#include using namespace std; int main() { int n,m,p[200],q[200]; cin >> n >> m; for(int i = 0; i < m; i++){ cin >> p[i] >> q[i]; if(p[i] == n) n = q[i]; else if(q[i] == n) n = p[i]; } cout << n << endl; return 0; }