from bisect import bisect_left N = int(input()) LR = [list(map(int,input().split())) for _ in range(N)] LR.sort(key = lambda x:x[1]) now = 0 ans = N L = [] for l,r in LR: a = bisect_left(L,l + 1) if L and a < len(L): if L[a] < r: L[a] = r else: L.append(r) print(N - len(L))