@staticmethod
def d():
    (n, *wh) = map(int, sys.stdin.read().split())
    wh = sorted(zip(*([iter(wh)] * 2)), key=(lambda x: ((- x[0]), x[1])))
    w = [x[1] for x in wh][::(- 1)]
    res = ([inf] * n)
    for x in w:
        res[bi_l(res, x)] = x
    print(bi_l(res, inf))
@staticmethod
def d():
    (n, *wh) = map(int, sys.stdin.read().split())
    wh = sorted(zip(*([iter(wh)] * 2)), key=(lambda x: ((- x[0]), x[1])))
    w = [x[1] for x in wh][::(- 1)]
    res = ([inf] * n)
    for x in w:
        res[bi_l(res, x)] = x
    print(bi_l(res, inf))