n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
a.sort(key = lambda x:x[1])
count = 0
l, r = -float("inf"), float("inf")
while len(a) > 0:
x, y = a.pop()
if max(l,x) <= min(y,r):
l, r = max(l,x), min(y,r)
else:
count += 1
l, r = x, y
print(count+1)