#include "iostream" using namespace std; int main() { int n,m,p,q; cin>>n; cin>>m; while (m--){ cin>>p>>q; if (n == p){ n = p; } else if (n==q) { n = q; } } cout<