#include using namespace std; const long long MOD = 998244353; int main(){ int N, Q; cin >> N >> Q; vector L(Q), R(Q); for (int i = 0; i < Q; i++){ cin >> L[i] >> R[i]; L[i]--; } vector X; X.push_back(0); X.push_back(N); for (int i = 0; i < Q; i++){ X.push_back(L[i]); X.push_back(R[i]); } sort(X.begin(), X.end()); X.erase(unique(X.begin(), X.end()), X.end()); int M = X.size(); for (int i = 0; i < Q; i++){ L[i] = lower_bound(X.begin(), X.end(), L[i]) - X.begin(); R[i] = lower_bound(X.begin(), X.end(), R[i]) - X.begin(); } vector imos(M + 1, 0); for (int i = 0; i < Q; i++){ imos[L[i]]++; imos[R[i]]--; } for (int i = 0; i < M; i++){ imos[i + 1] += imos[i]; } bool ok = true; for (int i = 0; i < M - 1; i++){ if (imos[i] > 0 && (X[i + 1] - X[i]) % 2 == 1){ ok = false; } } if (!ok){ cout << 0 << endl; } else { vector A; int N2 = 0; for (int i = 0; i < M - 1; i++){ if (imos[i] > 0){ A.push_back(X[i + 1] - X[i]); } else { N2 += X[i + 1] - X[i]; } } vector inv(N + 1); inv[1] = 1; for (int i = 2; i <= N; i++){ inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; } vector fact(N + 1), finv(N + 1); fact[0] = 1; finv[0] = 1; for (int i = 1; i <= N; i++){ fact[i] = fact[i - 1] * i % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } long long ans = 1; for (int a : A){ a /= 2; ans *= fact[a * 2] % MOD * finv[a] % MOD * finv[a + 1] % MOD; ans %= MOD; } if (N2 >= 2){ if (N2 % 2 == 0){ long long x = fact[N2] * finv[N2 / 2] % MOD * finv[N2 / 2] % MOD; long long y = fact[N2] * finv[N2 / 2 + 1] % MOD * finv[N2 / 2 - 1] % MOD; ans *= x + MOD - y; ans %= MOD; } else { long long x = fact[N2] * finv[(N2 + 1) / 2] % MOD * finv[(N2 - 1) / 2] % MOD; long long y = fact[N2] * finv[(N2 + 1) / 2 + 1] % MOD * finv[(N2 - 1) / 2 - 1] % MOD; ans *= x + MOD - y; ans %= MOD; } } ans *= fact[N / 2]; ans %= MOD; ans *= fact[(N + 1) / 2]; ans %= MOD; cout << ans << endl; } }