N=int(input()) A=[] for i in range(N): l,r=map(int,input().split()) A.append((l,r)) from itertools import permutations L=[i for i in range(N)] result=0 for P in permutations(L): x=0 ans=True for i in range(N): pos=P[i] l,r=A[pos][0],A[pos][1] if x<=l: x=l elif l<=x<=r: x+=0 else: ans=False if ans==True: result+=1 print(result)