N = int(input())
total_list=[]
for i in range(N):
num_list = list(map(int,input().split()))
total_list.append(num_list)
total_list.sort(key=lambda x:(x[1],x[0]))
#print(total_list)
start =0
end = 0
count = 0
for i in range(N):
now_start , now_end = total_list[i]
if now_start < end:
continue
else:
end = now_end
count+=1
print(count)
2
4 4
1 4
answer : 2