n=int(input())a=[[0 for i in range(2)] for j in range(n)]for i in range(n): a[i][0],a[i][1]=list(map(int,input().split()))a.sort(key=(lambda x: (x[1],x[0])))x=a[0][1]c=1for i in range(1,n): if a[i][0]>=x: x=a[i][1] c+=1print(c)