#include using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) int main(void) { int n, m; cin >> n >> m; vector p(m), q(m); rep(i, m) { cin >> p[i] >> q[i]; if (n == p[i]) n = q[i]; else if (n == q[i]) n = p[i]; } cout << n << '\n'; return 0; }