#include using namespace std; int main() { int N, M; bool cap[3] = {}; cin >> N; cap[--N] = true; cin >> M; while(M--) { int P, Q; cin >> P >> Q; swap(cap[--P], cap[--Q]); } cout << find(begin(cap), end(cap), true) - cap + 1 << endl; }