if __name__ == '__main__':
res, ed = 0, -float('inf')
ra = []
n = int(input())
for i in range(n):
l,r = map(int,input().split())
ra.append([r,l])
ra.sort()
for i in range(n):
if ra[i][1] > ed:
res += 1
ed = ra[i][0]
print(res)