N,K = map(int,input().split()) l = [] for _ in range(N): L,R = map(int,input().split()) l.append((L,1)) l,append((R,-1)) l.sort() tmp = 1 num = 0 P = 998244353 for t,i in l: if i == 1: tmp *= (K - num) tmp %= P num += 1 else: num -= 1 ans = pow(K,N,P) - tmp print(ans%P)