#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include using namespace std; using namespace atcoder; using mint = modint998244353; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; mint ans_comp = 1; vector> event; for( int i = 0; i < N; i++ ) { int L, R; cin >> L >> R; event.emplace_back(make_pair(L, 1)); event.emplace_back(make_pair(R, -1)); } sort(event.begin(), event.end()); mint cnt = 0; for( auto& p : event ) { if( p.second == 1 ) { ans_comp *= K-cnt; } cnt += p.second; } cout << (mint(K).pow(N)-ans_comp).val() << endl; }