import sys input = sys.stdin.readline from operator import itemgetter from heapq import heappop,heappush N=int(input()) AB=[list(map(int,input().split())) for i in range(N)] AB.sort(key=itemgetter(0)) H=[] for a,b in AB: if H: if H[0]<=a: heappop(H) heappush(H,b) else: heappush(H,b) else: heappush(H,b) print(len(H)-1)