#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define rep(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a, b) for (int(i) = (int)(b)-1; (i) >= (int)(a); (i)--) using ll = long long; using mint = modint998244353; int main() { int h, w; cin >> h >> w; int factsz = 2 * w + 1; vector fact(factsz), ifact(factsz); fact[0] = 1; rep(i, 1, factsz) fact[i] = fact[i - 1] * i; ifact[factsz - 1] = fact[factsz - 1].inv(); rrep(i, 1, factsz) ifact[i - 1] = ifact[i] * i; vector f(w + 1, 0); f[0] = fact[w]; rep(i, 0, h) { ll a, b; cin >> a >> b; vector g(w + 1); mint fallfact_a = 1, fallfact_b = 1; rep(i, 0, w) { fallfact_a *= w + a - 1 - i; fallfact_b *= w + b - i; } rep(i, 0, w + 1) { g[i] = (fallfact_b - fallfact_a) * ifact[i] * ifact[i + w]; fallfact_a *= a - 1 - i; fallfact_b *= b - i; } f = convolution(f, g); f.resize(w + 1); } cout << f[w].val() << endl; }