

def binSearch(S, x):

    a = -1

    b = len(S)-1



    while(a + 1 < b):

        c = (a+b)//2

        if S[c] >= x:

            a = c

        else:

            b = c



    return b



def main():

    N = int(eval(input()))

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



    S = []



    for a in A:

        if len(S) == 0 or S[-1] >= a:

            S.append(a)

        else:

            p = binSearch(S, a)

            S[p] = a

    

    print((len(S)))





if __name__ == '__main__':

    main()

#  --*-coding:utf-8-*--



import bisect



N = int(eval(input()))

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



Q = []

x = 0



for a in A:

    idx = bisect.bisect_right(Q, -a)



    if idx >= len(Q):

        x += 1

        Q.append(-a)

    else:

        Q[idx] = -a



print(x)

    

        

def binSearch(S, x):
    a = -1
    b = len(S) - 1
    while a + 1 < b:
        c = (a + b) // 2
        if S[c] >= x:
            a = c
        else:
            b = c
    return b


def main():
    N = int(eval(input()))
    A = [int(eval(input())) for _ in range(N)]
    S = []
    for a in A:
        if len(S) == 0 or S[-1] >= a:
            S.append(a)
        else:
            p = binSearch(S, a)
            S[p] = a
    print((len(S)))


if __name__ == "__main__":
    main()

#  --*-coding:utf-8-*--
import bisect

N = int(eval(input()))
A = [int(eval(input())) for _ in range(N)]
Q = []
x = 0
for a in A:
    idx = bisect.bisect_right(Q, -a)
    if idx >= len(Q):
        x += 1
        Q.append(-a)
    else:
        Q[idx] = -a
print(x)

-def binSearch(S, x): -    a = -1 -    b = len(S) - 1 -    while a + 1 < b: -        c = (a + b) // 2 -        if S[c] >= x: -            a = c -        else: -            b = c -    return b +#  --*-coding:utf-8-*-- +import bisect - -def main(): -    N = int(eval(input())) -    A = [int(eval(input())) for _ in range(N)] -    S = [] -    for a in A: -        if len(S) == 0 or S[-1] >= a: -            S.append(a) -        else: -            p = binSearch(S, a) -            S[p] = a -    print((len(S))) - - -if __name__ == "__main__": -    main() +N = int(eval(input())) +A = [int(eval(input())) for _ in range(N)] +Q = [] +x = 0 +for a in A: +    idx = bisect.bisect_right(Q, -a) +    if idx >= len(Q): +        x += 1 +        Q.append(-a) +    else: +        Q[idx] = -a +print(x)