#include using namespace std; constexpr int mod = 998244353; long long fac[200005], finv[200005], inv[200005]; void COMinit() { fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1; for (int i = 2; i < 200005; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } long long choose(int n,int k) { if(n < 0 || k < 0) return 0; if(n == 0) return 1; return COM(n+k-1,k-1); } long long modpow(long long a,long long b) { long long ans = 1; while(b) { if(b & 1) { (ans *= a) %= mod; } (a *= a) %= mod; b /= 2; } return ans; } void mpl(int &x,int y) { x += y; if(x >= mod) x -= mod; } int c[200200]; int main() { COMinit(); int N,Q; cin >> N >> Q; vectorL(Q),R(Q); for(int i = 0; i < Q; i++) { cin >> L[i] >> R[i]; if((R[i]-L[i]+1)%2 == 1) { cout << 0 << endl; return 0; } } c[0] = 1; for(int i = 2; i <= N+1; i += 2) { c[i] = (COM(i,i/2)+mod-COM(i,i/2-1))%mod; } vectorcmp; for(int i = 0; i < Q; i++) { cmp.push_back(L[i]); cmp.push_back(R[i]+1); for(int j = i+1; j < Q; j++) { if(L[i]%2 != L[j]%2) { cout << 0 << endl; return 0; } } } sort(cmp.begin(),cmp.end()); cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end()); if(cmp.empty()) { if(N%2 == 0) { cout << c[N]*fac[N/2]%mod*fac[N/2]%mod << endl; } else { cout << c[N+2]*fac[N/2+1]%mod*fac[N/2]%mod << endl; } return 0; } vectorsum(cmp.size()+1); for(int i = 0; i < Q; i++) { int it1 = lower_bound(cmp.begin(),cmp.end(),L[i])-cmp.begin(); int it2 = lower_bound(cmp.begin(),cmp.end(),R[i]+1)-cmp.begin(); sum[it1]++; sum[it2]--; } int ans = 1,cnt = 0; for(int i = 0; i+1 < cmp.size(); i++) { sum[i+1] += sum[i]; if(sum[i] == 0) { cout << "OK" << endl; continue; } cnt += cmp[i+1]-cmp[i]; ans = 1ll*ans*c[cmp[i+1]-cmp[i]]%mod; } if(N%2 == 0) { ans = 1ll*ans*c[N-cnt]%mod*fac[N/2]%mod*fac[N/2]%mod; } else { ans = 1ll*ans*c[N-cnt+1]%mod*fac[N/2+1]%mod*fac[N/2]%mod; } cout << ans << endl; }