#include #include "atcoder/all" #define debug cout << "OK" << endl; template inline bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; } inline int Code(char c) { if ('A' <= c and c <= 'Z')return (int)(c - 'A'); if ('a' <= c and c <= 'z')return (int)(c - 'a'); if ('0' <= c and c <= '9')return (int)(c - '0'); assert(false); } using namespace std; using namespace atcoder; #define int long long constexpr int MOD = 998244353; constexpr int INF = (1LL << 62); using minit = modint998244353; template ostream& operator << (ostream& st, const vector &v) { for (const T value : v) { st << value << " "; } return st; } template istream& operator >> (istream& st, vector& v) { for (T &value : v) { st >> value; } return st; } // int modpow(int a, int b, int m) { int res = 1; int q = a; for (int bit = 0; bit < 63; bit++) { if (b & (1ll << bit))res *= q; res %= m; q = q * q; q %= m; } return res; } //1-indexedですよ???????? template struct BIT { long long n; // 配列の要素数(数列の要素数+1) vector bit; // データの格納先 BIT(long long n_) : n(n_ + 1), bit(n, 0) {} void add(long long pos, long long c) { while (pos <= n) { bit[pos] += c; pos += pos & (-pos); } } T sum(long long pos) { T ans = 0; while (pos) { ans += bit[pos]; pos -= pos & (-pos); } return ans; } }; // void solve() { //#1 入力 int N, K; cin >> N >> K; vector> dat(N); for (int i = 0; i < N; i++) { cin >> dat[i].first >> dat[i].second; } //#2 sort,BITの初期化 sort(dat.begin(), dat.end()); BIT bit(200010); //#3 Rの記録,ansの算出 minit ans = 1; for (int i = 0; i < N; i++) { ans *= K - (bit.sum(200010) - bit.sum(dat[i].first)); bit.add(dat[i].second, 1); } //#4 出力 cout << (modpow(K, N, MOD) - ans.val() + MOD) % MOD << endl; } signed main() { int T = 1; // cin >> T; for (int i = 0; i < T; i++) solve(); return 0; }