#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll MOD = 998244353; ll mod_pow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) { res = res * x % mod; } x = x * x % mod; n >>= 1; } return res; } struct Node { int l; int r; Node(int l = -1, int r = -1) { this->l = l; this->r = r; } bool operator>(const Node &n) const { return l > n.l; } }; struct Node2 { int l; int r; Node2(int l = -1, int r = -1) { this->l = l; this->r = r; } bool operator>(const Node2 &n) const { return r > n.r; } }; int main() { ll N, K; cin >> N >> K; int L[N]; int R[N]; priority_queue , greater> pque_1; for (int i = 0; i < N; ++i) { cin >> L[i] >> R[i]; pque_1.push(Node(L[i], R[i])); } ll all = mod_pow(K, N); ll cnt = 1; priority_queue , greater> pque_2; while (not pque_1.empty()) { Node node = pque_1.top(); pque_1.pop(); while (not pque_2.empty() && pque_2.top().r <= node.l) { pque_2.pop(); } ll m = pque_2.size(); cnt *= (K - m); cnt %= MOD; pque_2.push(Node2(node.l, node.r)); } cout << (all - cnt + MOD) % MOD << endl; return 0; }