import bisect

def lis(n, a):
    l = []
    l.append(a[0])
    length = 1
    for i in range(1, n):
        if l[length - 1] < a[i]:
            l.append(a[i])
            length += 1
        else:
            l[bisect.bisect_left(l, a[i], lo=0, hi=length)] = a[i]

    return length

if __name__ == '__main__':
    n = int(input())
    a = [int(input()) for i in range(n)]

    print(lis(n, a))
