def _input(n):
    return [int(raw_input()) for i in xrange(n)]

def linear_lower_bound(arr, n, target):
    p = -1
    for i in xrange(n):
        if arr[i] <= target:
            p = i
    print p
    return p+1

def LIS(arr):
    L = [0] * len(arr)
    L[0] = arr[0]
    length = 1

    for i in xrange(1, len(arr)):
        #if len(L) == 0: L.append(i)
        if arr[i] > L[length - 1]:
            L[length] = arr[i]#L.append(A[i])
            length += 1
        else:
            L[linear_lower_bound(L, length, arr[i])] = arr[i]
    return len(L), L

#==============================================
def main():
    n = int(raw_input())
    arr = _input(n)
    print LIS(arr)

if __name__ == "__main__":
    main()