import heapq
n = int(input())
a = []
for _ in range(n):
x, y = map(int, input().split())
a.append([x,y])
a.sort(lambda x: (x[0],x[1]))
ans = []
heapq.heappush(ans, a[0][1])
for i in range(1,len(a)):
cur = heapq.heappop(ans)
if cur < a[i][0]:
heapq.heappush(ans,a[i][1])
else:
heapq.heappush(ans,cur)
heapq.heappush(ans,a[i][1])
print(len(ans))