n, k = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(n)] LR.append([10**6, 10**6 + 1]) mod = 998244353 P = [k % mod for _ in range(n + 1)] for i in range(1, n + 1): P[i] = P[i - 1] * (k - i) % mod LR.sort(key=lambda x: (x[1], x[0])) ans = 0 num = 0 res = 0 l, r = -1, -1 for i in range(n + 1): if l == -1 and r == -1: l, r = LR[i] r -= 1 num += 1 elif r < LR[i][0]: if num > 1: if ans == 0: ans = 1 ans *= (pow(k, num, mod) - P[num]) % mod ans %= mod else: res += 1 l, r = LR[i] r -= 1 num = 1 else: l = min(l, LR[i][0]) r = max(r, LR[i][1] - 1) num += 1 if i == n - 1: ans *= pow(k, res, mod) ans %= mod print(ans)