import sys
import heapq
N = int(input())
lec = []
for i in range(N):
a, b = map(int, sys.stdin.readline().split())
heapq.heappush(lec, (b, a)) #min heap based on the end time
end = 0
ans = 0
while lec:
l = heapq.heappop(lec)
if end <= l[1]:
ans += 1
end = l[0]
print(ans)
heap
단순 sorting보다는 min heap을 쓰는 것이 더 빠르다