import itertools N = int(input()) junretu = itertools.permutations(range(N),N) lst = [] for i in range(N): a,b = map(int,input().split()) lst.append((a,b)) cnt = 0 for j in junretu: now = 0 check = True for k in range(N): if now > lst[j[k]][1]: check = False break else: now = max(now,lst[j[k]][0]) if check: #print(j) cnt += 1 print(cnt)