n=int(input())
lst1=[]
lst2=[]
for i in range(n):
lst1.append([])
a,b=map(int,input().split())
lst1[i].append(a)
lst1[i].append(b)
if n==1:
print("1")
else:
lst2.append(lst1[0])
for i in range(1,n):
flag=0
for j in range(0,len(lst2)):
if lst1[i][0]<=lst2[j][0] and lst1[i][1]<=lst2[j][1]:
lst2[j]=lst1[i]
flag=1
break
elif lst1[i][0]<=lst2[j][1] and lst1[i][1]<=lst2[j][0]:
lst2[j]=lst1[i]
flag=1
break
if flag==0:
lst2.append(lst1[i])
print(len(lst2))