import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

A = [0] * N
for i in range(N):
    A[i] = int(input())

dp = [0] * N

dp[0] = A[0]
cur = 1
for i in range(1, N):
    left = -1
    right = cur
    while right - left > 1:
        mid = left + (right - left) // 2
        if dp[mid] < A[i]:
            left = mid
        else:
            right = mid
    if cur == right:
        cur += 1
    dp[right] = A[i]
print(cur)

    
