#include <stdio.h>
#define MAX 100000
#define INF 100000000
int N;
int a[MAX];
int dp[MAX];
int max(int a,int b){
  return a>b?a:b;
}
int l_bound(int x){
  int l,h,m;
  l=0;
  int i;
  h=N-1;
  while(h-l>1){
    m=(l+h)/2;
    if(dp[m]>=x)h=m;
    else l=m;
  }
  if(dp[l]<x)return h;
  else return l;
}
int main(){
  int i,j,k;
  int res=0;
  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&a[i]);
  for(i=0;i<N;i++)dp[i]=INF;
  for(i=0;i<N;i++){
    j=l_bound(a[i]);
    dp[j]=a[i];
    //for(k=0;k<N;k++)printf("%d ",dp[k]);
    //printf("\n");
  }
  i=0;
  while(dp[i]<INF && i<N)i++;
  printf("%d\n",i);
  return 0;
}