#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

int main(){
  int N; cin >> N;
  vector<ll> A(N); vector<ll> vec(N,INF);
  for(int i = 0; i < N; i++){ cin >> A[i];}
  int cnt  = 0;
  for(int i = 0; i < N; i++){
    int c= lower_bound(vec.begin(),vec.end(),A[i]) - vec.begin();
    vec[c] = A[i];
    cnt = max(cnt, c);}
  
  cout << cnt + 1 << endl; return 0;}
