#include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int N,M; cin >> N >> M; int ans = 4; if(M == 0) ans += N % 2; else if(M == 1) ans = 5; else rep(t,1){ set> uv; set u_v; rep(i,M){ int u,v; cin >> u >> v; u--; v--; uv.insert(make_pair(u,v)); u_v.insert(u); u_v.insert(v); } vector uvvec(u_v.begin(), u_v.end()); if(M != uvvec.size()){ ans = 5; break; } rep(i,M-1) if(0 == uv.count({ uvvec[i],uvvec[i+1] })){ ans = 5; break; } if(!uv.count({ uvvec.front(), uvvec.back() })){ ans = 5; break; } rep(i,M-1) if((uvvec[i+1] - uvvec[i]) % 2 == 0){ ans = 5; break; } if((uvvec.front() + N - uvvec.back()) % 2 == 0){ ans = 5; break; } } cout << ans << endl; return 0; } struct ios_do_not_sync { ios_do_not_sync() { ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;