#include using namespace std; typedef long long ll; typedef pair P; const int INF = 1e9; const int mod = 1e9+7; const double EPS = 1e-10; const double PI = acos(-1.0); int main() { int n,m; cin >> n >> m; for(int i = 0; i < m; i++){ int l,r; cin >> l >> r; if(n == l) n = r; else if(n == r) n = l; } cout << n << endl; return 0; }