import bisect

N = int(input())
Ali = [int(input()) for _ in range(N)]
dp = [10**10]*N
dp[0] = Ali[0]

for i in range(1,N):
  a = Ali[i]
  if a > dp[i-1]:
    dp[i] = a
  else:
    dp[bisect.bisect_left(dp, a)] = a
    
print(bisect.bisect_left(dp, 10**10))
