#include #include #define SEGT_SIZE 262144 int cmp_int (const void *ap, const void *bp) { int a = *(int *)ap; int b = *(int *)bp; if (a < b) { return -1; } if (a > b) { return 1; } return 0; } long long power_mod (long long a, long long b, long long mod_num) { long long ans = 1LL; if (b > 0LL) { ans = power_mod(a, b/2LL, mod_num); ans = (ans * ans) % mod_num; if (b%2LL == 1LL) { ans = (ans * (a % mod_num)) % mod_num; } } return ans; } void set_segt (int *t, int idx, int val, int size) { idx = idx+size-1; t[idx] = val; while (idx > 0) { idx = (idx-1)/2; t[idx] = t[2*idx+1]+t[2*idx+2]; } return; } int sum_segt_rec (int *t, int a, int b, int k, int l, int r) { int ans = 0; if (r <= a || b <= l) { return 0; } if (a <= l && r <= b) { return t[k]; } ans = sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2); ans += sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r); return ans; } int sum_segt (int *t, int a, int b, int size) { return sum_segt_rec(t, a, b, 0, 0, size); } int main () { int n = 0; long long k = 0LL; int lr[100000][2] = {}; int res = 0; long long ans = 1LL; long long mod_num = 998244353LL; int t[2*SEGT_SIZE-1] = {}; res = scanf("%d", &n); res = scanf("%lld", &k); for (int i = 0; i < n; i++) { res = scanf("%d", lr[i]); res = scanf("%d", lr[i]+1); } qsort(lr, n, sizeof(int)*2, cmp_int); for (int i = 0; i < n; i++) { int cnt = sum_segt(t, 0, lr[i][0], SEGT_SIZE); int num = sum_segt(t, lr[i][1]-1, lr[i][1], SEGT_SIZE); if (k >= ((long long)(i-cnt))) { ans *= k-((long long)(i-cnt)); ans %= mod_num; } else { ans = 0LL; } set_segt(t, lr[i][1]-1, num+1, SEGT_SIZE); } ans = mod_num-ans; ans += power_mod(k, (long long)n, mod_num); printf("%lld\n", ans%mod_num); return 0; }