#include #include #include #include using namespace std; int main() { int n, m; cin >> n >> m; n--; int p,q; vector vec(3, 0); vec.at(n) = 1; for (int i = 0; i < m; ++i) { cin >> p >> q; --p; --q; swap(vec.at(p), vec.at(q)); } auto ans = distance(vec.begin(), find(vec.begin(), vec.end(), 1)); ans++; cout << ans << endl; return 0; }