from bisect import bisect 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(L,l) if L and a < len(L): if L[a] > r: L[a] = r else: L.append(r) #print(l,r,L) print(N - len(L))