mod=998244353 n,k=map(int,input().split()) L=[] R=[] for i in range(n): l,r=map(int,input().split()) L.append(l) R.append(r) L.sort(reverse=True) R.sort(reverse=True) r_ans=1 n_c=0 while(L): l=L.pop() r=R.pop() if l