from collections import deque, defaultdict, Counter from bisect import bisect_left, bisect_right from itertools import permutations, combinations from heapq import heappop, heappush import math, sys # input = sys.stdin.readline _int = lambda x: int(x)-1 MOD = 998244353 #10**9+7 INF = 1<<60 Yes, No = "Yes", "No" N = int(input()) LR = [] for _ in range(N): l, r = map(int, input().split()) LR.append((l, r)) ans = 0 for p in permutations(range(N)): x = 0 for i in range(N): l, r = LR[p[i]] if x > r: break x = max(x, l) else: ans += 1 print(ans)