from itertools import permutations N=int(input()) mem=[] for i in range(N): L, R = (int(x) for x in input().split()) mem.append([L, R]) ans=0 for i in permutations(mem): ok=True S=[] for j in range(1, N): if i[j-1][0] <= i[j][1]: continue else: ok = False if ok: idx = 1 x = 1 while x <= 3854 and idx <= N-1: if i[idx-1][0] <= x <= i[idx][1]: S.append(x) idx += 1 else: x += 1 S.append(i[-1][1]) ok2 = True if len(S) < N: ok2 = False continue for i in range(1, N): if S[i-1] > S[i]: ok2 = False if ok2: ans += 1 print(ans)