#include using namespace std; #define rep(i,n) for (int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() using ll=long long; using pll=pair; using tll=tuple; const ll INF=(1ll<<60); template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> n >> k; vector p(n); rep(i,n) cin >> p[i].first >> p[i].second; sort(all(p)); ll r=1,x=k; priority_queue,greater> pq; for(auto &[a,b]:p){ while(!pq.empty()&&pq.top()<=a){ pq.pop(); x++; } r*=x; r%=mod; x=max(0ll,x-1); pq.push(b); } cout << (modpow(k,n,mod)-r+mod)%mod << endl; }