from itertools import permutations N=int(input()) mem=[] for _ in range(N): L, R = map(int, input().split()) mem.append([L, R]) ans=0 for perm in permutations(mem): idx = 0 x = 1 S = [] while x <= 3854 and idx < N: if perm[idx][0] <= x <= perm[idx][1]: S.append(x) idx += 1 x += 1 if len(S) == N: # 全部埋まった ok = True for j in range(1, N): if S[j-1] > S[j]: ok = False break if ok: ans += 1 print(ans)