#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main() {
  int N;
  cin>>N;
  vector<int> l(N, INT_MAX);
  for (int i=0;i<N;++i) {
    int a;
    cin>>a;
    int pos = distance(l.begin(),lower_bound(l.begin(),l.end(),a));
    l[pos] = a;
  }

  int idx = l.size();
  while(l[--idx] == INT_MAX);
  cout<<idx+1<<endl;

  return 0;
}
