#include #include using namespace std; const long long MOD = 998244353; int main(){ int H, W; cin >> H >> W; vector A(H), B(H); for (int i = 0; i < H; i++){ cin >> A[i] >> B[i]; } vector inv(W * 2 + 1); inv[1] = 1; for (int i = 2; i <= W * 2; i++){ inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; } vector fact(W * 2 + 1); vector finv(W * 2 + 1); fact[0] = 1; finv[0] = 1; for (int i = 1; i <= W * 2; i++){ fact[i] = fact[i - 1] * i % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } vector> f(H, vector(W + 1, 0)); for (int i = 0; i < H; i++){ long long a = 1, b = 1; for (int j = B[i] + 1; j <= B[i] + W; j++){ b *= j; b %= MOD; } for (int j = A[i]; j <= A[i] + W - 1; j++){ a *= j; a %= MOD; } for (int j = 0; j <= W && j <= B[i]; j++){ int B2 = B[i] - j; f[i][j] = b * finv[W + j] % MOD; b *= B[i] - j; b %= MOD; if (A[i] > j){ int A2 = A[i] - j - 1; f[i][j] += MOD - a * finv[W + j] % MOD; f[i][j] %= MOD; a *= A[i] - j - 1; a %= MOD; } } } for (int i = 0; i < H; i++){ for (int j = 0; j <= W; j++){ f[i][j] *= finv[j]; f[i][j] %= MOD; } } vector g(W + 1, 0); g[0] = 1; for (int i = 0; i < H; i++){ g = atcoder::convolution(g, f[i]); g.resize(W + 1); } cout << g[W] * fact[W] % MOD << endl; }