#include using namespace std; int main() { int n, m; cin >> n >> m; int ans[3] = {}; ans[--n] = 1; for (int _ = 0; _ < m; _++) { int i, j; cin >> i >> j; swap(ans[--i], ans[--j]); } if (ans[0] == 1) cout << 1 << '\n'; else if (ans[1] == 1) cout << 2 << '\n'; else cout << 3 << '\n'; return 0; }