#include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; const ll modc = 998244353; long long mod_exp(long long b, long long e, long long m){ if (e > 0 && b == 0) return 0; long long ans = 1; b %= m; while (e > 0){ if ((e & 1LL)) ans = (ans * b) % m; e = e >> 1LL; b = (b*b) % m; } return ans; } int main(){ ll N, K, t, x, L, R, now=0, ans=1; cin >> N >> K; vector> e(N*2); for (int i=0; i> L >> R; e[2*i] = {L, 1}; //in e[2*i+1] = {R, 0}; //out } sort(e.begin(), e.end()); for (int i=0; i<2*N; i++){ tie(x, t) = e[i]; if (t == 0) now--; else{ ans *= (K-now); ans %= modc; now++; } } cout << (modc + mod_exp(K, N, modc) - ans) % modc << endl; return 0; }