#LIS

n=int(eval(input()))

lists=[0]*n

for i in range(n):

    lists[i]=int(eval(input()))

import bisect

counter=0

lislist=[lists[-1]]

for i in range(2,n+1):

    a=lists[-i]

    index=bisect.bisect_right(lislist,a)

    if index<len(lislist):

        lislist[index]=a



    elif index==len(lislist):

        lislist.append(a)



print((len(lislist)))

#!/usr/bin/env python

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

# sequence decomposing

import bisect

n = int(eval(input()))

lists = [int(eval(input())) for _ in range(n)]

lists = lists[::-1]

dataset = []

dataset.append(lists[0])

# datasetは単調増加なリストの値

for i in range(1, n):

    x = lists[i]

    if x >= dataset[-1]:

        dataset.append(x)

    elif x < dataset[-1]:

        index = bisect.bisect_right(dataset, x)

        dataset[index] = x

print((len(dataset)))
# LIS
n = int(eval(input()))
lists = [0] * n
for i in range(n):
    lists[i] = int(eval(input()))
import bisect

counter = 0
lislist = [lists[-1]]
for i in range(2, n + 1):
    a = lists[-i]
    index = bisect.bisect_right(lislist, a)
    if index < len(lislist):
        lislist[index] = a
    elif index == len(lislist):
        lislist.append(a)
print((len(lislist)))

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# sequence decomposing
import bisect

n = int(eval(input()))
lists = [int(eval(input())) for _ in range(n)]
lists = lists[::-1]
dataset = []
dataset.append(lists[0])
# datasetは単調増加なリストの値
for i in range(1, n):
    x = lists[i]
    if x >= dataset[-1]:
        dataset.append(x)
    elif x < dataset[-1]:
        index = bisect.bisect_right(dataset, x)
        dataset[index] = x
print((len(dataset)))

-# LIS -n = int(eval(input())) -lists = [0] * n -for i in range(n): -    lists[i] = int(eval(input())) +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# sequence decomposing -counter = 0 -lislist = [lists[-1]] -for i in range(2, n + 1): -    a = lists[-i] -    index = bisect.bisect_right(lislist, a) -    if index < len(lislist): -        lislist[index] = a -    elif index == len(lislist): -        lislist.append(a) -print((len(lislist))) +n = int(eval(input())) +lists = [int(eval(input())) for _ in range(n)] +lists = lists[::-1] +dataset = [] +dataset.append(lists[0]) +# datasetは単調増加なリストの値 +for i in range(1, n): +    x = lists[i] +    if x >= dataset[-1]: +        dataset.append(x) +    elif x < dataset[-1]: +        index = bisect.bisect_right(dataset, x) +        dataset[index] = x +print((len(dataset)))