import bisect

from collections import deque

N = int(eval(input()))

ans = deque()



for _ in range(N):

    a = int(eval(input()))

    ind = bisect.bisect_left(ans, a)

    if ind == 0:

        ans.appendleft(a)

    else:

        ans[ind-1] = a

print((len(ans)))

import sys

input = sys.stdin.readline

from bisect import bisect_left

from collections import deque



def main():

    N = int(eval(input()))

    counter = deque([])

    for _ in range(N):

        a = int(eval(input()))

        ind = bisect_left(counter, a)

        if ind == 0:

            counter.appendleft(a)

        else:

            counter[ind-1] = a

    print((len(counter)))





if __name__ == '__main__':

    main()
import bisect
from collections import deque

N = int(eval(input()))
ans = deque()
for _ in range(N):
    a = int(eval(input()))
    ind = bisect.bisect_left(ans, a)
    if ind == 0:
        ans.appendleft(a)
    else:
        ans[ind - 1] = a
print((len(ans)))

import sys

input = sys.stdin.readline
from bisect import bisect_left
from collections import deque


def main():
    N = int(eval(input()))
    counter = deque([])
    for _ in range(N):
        a = int(eval(input()))
        ind = bisect_left(counter, a)
        if ind == 0:
            counter.appendleft(a)
        else:
            counter[ind - 1] = a
    print((len(counter)))


if __name__ == "__main__":
    main()

-import bisect +import sys + +input = sys.stdin.readline +from bisect import bisect_left -N = int(eval(input())) -ans = deque() -for _ in range(N): -    a = int(eval(input())) -    ind = bisect.bisect_left(ans, a) -    if ind == 0: -        ans.appendleft(a) -    else: -        ans[ind - 1] = a -print((len(ans))) + +def main(): +    N = int(eval(input())) +    counter = deque([]) +    for _ in range(N): +        a = int(eval(input())) +        ind = bisect_left(counter, a) +        if ind == 0: +            counter.appendleft(a) +        else: +            counter[ind - 1] = a +    print((len(counter))) + + +if __name__ == "__main__": +    main()