#include<iostream> #define maxn 110 #define maxm 2000010 #define ll long long usingnamespacestd;
constint p = 998244353;
ll pow_mod(ll x, ll n){ ll s = 1; for (; n; n >>= 1, x = x * x % p) if (n & 1) s = s * x % p; return s; }
int n, m, a[maxn], b[maxn];
ll fac[maxm], inv[maxm]; voidinit_C(int n){ fac[0] = 1; for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % p; inv[n] = pow_mod(fac[n], p - 2); for (int i = n - 1; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % p; }
ll C(int n, int m){ return n < m ? 0 : fac[n] * inv[m] % p * inv[n - m] % p; }
ll g[maxn][maxn]; intGauss(int n){ ll res = 1; for (int i = 1; i <= n; ++i) { int pos = -1; for (int j = i; j <= n; ++j) if (g[j][i]) pos = j; if (pos == -1) return0; swap(g[i], g[pos]); res *= pos == i ? 1 : -1; res = res * g[i][i] % p; ll inv = pow_mod(g[i][i], p - 2); for (int j = i + 1; j <= n; ++j) for (int k = n; k >= i; --k) g[j][k] = (g[j][k] - g[j][i] * inv % p * g[i][k]) % p; } return res; }
voidwork(){ cin >> n >> m; for (int i = 1; i <= m; ++i) cin >> a[i] >> b[i]; for (int i = 1; i <= m; ++i) for (int j = 1; j <= m; ++j) g[i][j] = C(b[j] - a[i] + n - 1, n - 1); cout << (Gauss(m) + p) % p << "\n"; }