'''
本质上还是LIS问题,变了一下形
过现在序列有两个,而且两个序列存在一一映射关系
可以看成一个序列的两个维度,先按照第一个维度进行排序,保证第一个维度
一定从左往右选是上升的,然后只需要用LIS的套路,求第二个维度的LIS长度
即可,需要一点思路的转换
'''
import bisect
N = int(input())
arr = []
for _ in range(N):
a, b = map(int, input().split())
arr.append( (a, b) )
arr.sort()
lst = []
for i in range(len(arr)):
idx = bisect.bisect_left(lst, arr[i][1])
if idx >= 0 and idx < len(lst):
lst[idx] = arr[i][1]
else:
lst.append(arr[i][1])
print(len(lst))