#include #define rep(i,a,n) for (int i = a;i < n;i++) using namespace std; int main(){ int n,m,p,q; cin >> n >> m; rep(i,0,m) { cin >> p >> q; if (q == n) n = p; if (p == n) n = q; } cout << n << endl; }