时间复杂度 $O(nlogn)$
n = int(input())
lt = [list(map(int, input().split(" "))) for _ in range(n)]
lt.sort()
res = []
maxR = l[0][1]
maxL = l[0][0]
for i in lt:
l, r = i
if maxR >= lt:
maxR = max(r, maxR)
else:
res.append([maxL, maxR])
maxL = l
maxR = r
res.append([maxL, maxR])
print(len(res))