import bisect

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

# Wrapper for built-in function
def lower_bound(arr, target):
    return bisect.bisect_right(arr, target)


def LIS(arr, n):
    L = [0] * n

    L[0] = arr[0]
    length = 1

    for i in xrange(1, n):
        if L[length - 1] < arr[i]:
            L[length] = arr[i]#L.append(A[i])
            length += 1
        else:
            if L[lower_bound(L[:length], arr[i])-1] != arr[i]: # Fix common item - Dont insert common item
                L[lower_bound(L[:length], arr[i])] = arr[i]
    return length, L

#=========================================================
def main():
    n = int(raw_input())
    arr = _input(n)
    print LIS(arr, n)[0]

if __name__ == "__main__":
    main()