#include <bits/stdc++.h>
using namespace std;
int findSlot(vector<vector<int> > &tail, int d) {
  int l = -1;
  int h = tail.size() - 1;
  while (h - l != 1) {
    int m = (h + l) / 2;
    if (tail[m].back() >= d)
      h = m;
    else
      l = m;
  }
  return h;
}
int main() {
  int n;
  cin >> n;
  vector<int> digits(n);
  vector<vector<int> > tail;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    if (tail.empty()) {
      tail.push_back(vector<int>(1, d));
    } else if (d > tail.back().back()) {
      tail.push_back(tail.back());
      tail.back().push_back(d);
    } else {
      int toChange = findSlot(tail, d);
      tail[toChange][tail[toChange].size() - 1] = d;
    }
  }
  cout << tail.back().size() << endl;
}
