#include <bits/stdc++.h>
using namespace std;
vector<int> a;
int main() {
  int n, m, i, as = 0;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &i);
    m = lower_bound(a.begin(), a.end(), i) - a.begin();
    if (m == a.size())
      a.push_back(i);
    else
      a[m] = i;
  }
  printf("%d\n", a.size());
  return 0;
}
