from itertools import permutations N = int(input()) xs = [] for _ in range(N): L, R = map(int, input().split()) xs.append((L, R)) def is_valid(ps): p = xs[ps[0]][0] for i in range(1, N): l, r = xs[ps[i]] if p > r: return False p = max(p, l) return True ans = 0 for ps in permutations(range(N)): if is_valid(ps): ans += 1 print(ans)