n = int(input()) a = [] for i in range(n): temp = list(map(int, input().split())) a.append(temp) a.sort(key= lambda x: (x[1], x[0])) count = 0 now = 0 for i, j in a: if i >= now: count =count +1 now = j print(count)