N = int(eval(input()))

A = list(int(eval(input()))for i in range(N))

H = [A[0]]

for i in range(1,N):

    if A[i] <= H[-1]:

        H.append(A[i])

    else:

        l,r =0,len(H)

        while l != r :

            if H[(l+r)//2]>=A[i]:

                l = (l+r)//2+1

            else:

                r = (l+r)//2

        H[l] = A[i]

print((len(H)))

import bisect

N = int(eval(input()))

A = [int(eval(input()))for i in range(N)]

m = [-A[0]]

ans = 1

for i in A[1:]:

    p = bisect.bisect_left(m,-i+1)

    if p == ans:

        ans += 1

        m.append(-i)

    else:

        m[p] = -i

print(ans)

N = int(eval(input()))
A = list(int(eval(input())) for i in range(N))
H = [A[0]]
for i in range(1, N):
    if A[i] <= H[-1]:
        H.append(A[i])
    else:
        l, r = 0, len(H)
        while l != r:
            if H[(l + r) // 2] >= A[i]:
                l = (l + r) // 2 + 1
            else:
                r = (l + r) // 2
        H[l] = A[i]
print((len(H)))

import bisect

N = int(eval(input()))
A = [int(eval(input())) for i in range(N)]
m = [-A[0]]
ans = 1
for i in A[1:]:
    p = bisect.bisect_left(m, -i + 1)
    if p == ans:
        ans += 1
        m.append(-i)
    else:
        m[p] = -i
print(ans)

+import bisect + -A = list(int(eval(input())) for i in range(N)) -H = [A[0]] -for i in range(1, N): -    if A[i] <= H[-1]: -        H.append(A[i]) +A = [int(eval(input())) for i in range(N)] +m = [-A[0]] +ans = 1 +for i in A[1:]: +    p = bisect.bisect_left(m, -i + 1) +    if p == ans: +        ans += 1 +        m.append(-i) -        l, r = 0, len(H) -        while l != r: -            if H[(l + r) // 2] >= A[i]: -                l = (l + r) // 2 + 1 -            else: -                r = (l + r) // 2 -        H[l] = A[i] -print((len(H))) +        m[p] = -i +print(ans)