#include using namespace std; constexpr int mod = 998244353; long long modpow(long long a,long long b) { long long ans = 1; while(b) { if(b & 1) { (ans *= a) %= mod; } (a *= a) %= mod; b /= 2; } return ans; } template struct BinaryIndexedTree { int N; vectorbit; BinaryIndexedTree(){} BinaryIndexedTree(int x) { N = x; bit.resize(x+1); } void add(int x,T y) { x++; while(x <= N) { bit[x] += y; x += x&-x; } } T sum(int x) { x++; T res = 0; while(x) { res += bit[x]; x -= x&-x; } return res; } inline T sum(int l, int r) {//[l,r) return sum(r-1)-sum(l-1); } inline T operator[](int k) { return sum(k)-sum(k-1); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,K; cin >> N >> K; vectorL(N),R(N); for(int i = 0; i < N; i++) { cin >> L[i] >> R[i]; } long long ans = modpow(K,N); vector>tmp; for(int i = 0; i < N; i++) { tmp.push_back({L[i],R[i]}); } sort(tmp.begin(),tmp.end()); long long res = 1; BinaryIndexedTreebit(200200); for(int i = 0; i < N; i++) { int cnt = bit.sum(tmp[i].first,200200); res *= max(0,K-cnt); res %= mod; bit.add(tmp[i].second-1,1); } ans += mod-res; ans %= mod; cout << ans << endl; }