from itertools import permutations N = int(input()) p_s = [] for n in range(N): L, R = map(int, input().split()) p_s.append((L, R)) n_s = [n for n in range(1, N + 1)] n_ps = permutations(n_s, N) count = 0 for n_p in n_ps: is_true = True min_diff = 0 for n in range(N): now_p = p_s[n_p[n] - 1] l_diff = now_p[0] r_diff = now_p[1] if min_diff > r_diff: is_true = False break min_diff = max(min_diff, l_diff) if is_true: # print(n_p) count += 1 print(count)