import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 class Combinatorics(): def __init__(self, mod, maxi): self.mod = mod self.maxi = maxi self.facs = [1] * (maxi + 1) self.factinvs = [1] * (maxi + 1) self.invs = [1] * (maxi + 1) for i in range(2, self.maxi + 1): self.facs[i] = ((self.facs[i-1] * i) % self.mod) self.invs[i] = (-self.invs[self.mod % i] * (self.mod // i)) % self.mod self.factinvs[i] = (self.factinvs[i-1] * self.invs[i]) % self.mod def choose(self, n, k) -> int: if k < 0 or k > n: return 0 if k == 0 or k == n: return 1 k = min(k, n - k) return (((self.facs[n] * self.factinvs[k]) % self.mod) * self.factinvs[n-k]) % self.mod def perm(self, n, k) -> int: return (self.choose(n, k) * self.facs[k]) % self.mod def homop(self, n, k) -> int: if n == k == 0: return 1 return self.choose(n + k - 1, k) n, k = mi() LR = [li() for _ in range(n)] s = [[] for _ in range(2 * 10 ** 5 + 1)] t = [[] for _ in range(2 * 10 ** 5 + 1)] for i, v in enumerate(LR): l, r = v s[l].append(i) t[r].append(i) S = 0 C = Combinatorics(mod, 3 * 10 ** 5) ans = 1 for i in range(1, 2 * 10 ** 5 + 1): S -= len(t[i]) for x in range(len(s[i])): ans *= (k - S - x) ans %= mod ans *= C.invs[x + 1] ans %= mod S += len(s[i]) ans = pow(k, n, mod) - ans ans %= mod print(ans)