from bisect import bisect_left N = int(input()) A = list(map(int, input().split())) LIS = [] for a in A : if not len(LIS) or a > LIS[-1]: LIS.append(a) else: idx = bisect_left(LIS, a) LIS[idx] = a print(len(LIS))