from itertools import groupby, accumulate, combinations, permutations, product, combinations_with_replacement n = int(input().strip()) L = [] R = [] for i in range(n): l,r = map(int, input().split()) L.append(l) R.append(r) cnt = 0 for per in permutations(range(n)): flag = True now = 0 for num in per: now = max(now, L[num]) if now > R[num]: flag = False break if flag: cnt += 1 print(cnt)