from itertools import permutations N = int(input()) LR = [tuple(map(int, input().split())) for _ in range(N)] P = permutations(list(range(N))) ans = 0 Lmax = 0 for p in P: flag = True Lmax = 0 for i in range(N): L, R = LR[p[i]] if R < Lmax: flag = False Lmax = max(Lmax,L) if flag: ans += 1 print(ans)