#include <bits/stdc++.h>
using namespace std;
int mini[100005], sz;
int main() {
  int n;
  cin >> n;
  memset(mini, 127, sizeof(mini));
  mini[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int x, j = sz;
    cin >> x;
    for (; mini[j] > x; --j)
      ;
    mini[j + 1] = min(mini[j + 1], x);
    sz = max(sz, j + 1);
  }
  cout << sz;
  return 0;
}
