#include using namespace std; typedef unsigned long long ul; typedef signed long long ll; ul over = 1000000007; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cout << fixed; int n, m; cin >> n >> m; for (int i = 0; i < m; ++i) { int p, q; cin >> p >> q; if (n==p) n = q; else if (n==q) n = p; } cout << n << endl; return 0; }