import bisect

N = int(raw_input())

LIS = []

for i in range(N):
    a = int(raw_input())
    z = bisect.bisect_left(LIS, a)
    if z >= len(LIS):
        LIS.append(a)
    else:
        LIS[z] = a

print len(LIS)

