#include #define FOR(i,a,b) for(int i = (a); i < (b); ++i) using namespace std; int main() { int n, m; cin >> n >> m; FOR(i, 0, m) { int p, q; cin >> p >> q; if (n == p || n == q) n = (n != p) ? p : q; } cout << n << endl; return 0; }