#include <bits/stdc++.h>
using namespace std;
#define ul unsigned long long
#define ll long long
#define ld long double



int main()
{
  ll n,cv,dp[100000],ml=0;
  cin>>n;
  cin>>dp[0];
  for (ll i = 1; i < n; i++)
  {
    cin>>cv;
    if (dp[ml]<cv) {
      ml++;
      dp[ml]=cv;
    } else {
      *lower_bound(dp,dp+ml+1,cv)=cv;
    }
  }
  cout<<ml+1<<endl;

  return 0;
}

