n = int(input())
envlope = []
for _ in range(n):
    envlope.append(list(map(int, input().split())))
envlope.sort(key = lambda x: (x[0], -x[1]))
res = 0
ends = [0] * n
for _, length in envlope:
    l, r = 0, res
    while l < r:
        m = (l + r) // 2
        if ends[m] < length:
            l = m + 1
        else:
            r = m
    ends[r] = length
    if r == res:
        res += 1
print(res)