# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=ja
from bisect import bisect_left
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,*A = map(int, read().split())

    LIS = [A[0]]
    for a in A:
        if a > LIS[-1]:
            LIS.append(a)
        else:
            LIS[bisect_left(LIS, a)] = a

    ans = len(LIS)
    print(ans)


if __name__ == "__main__":
    main()
