#include <bits/stdc++.h>
using namespace std;
int main() {
  int(n);
  scanf("%d", &(n));
  int((a)[(n)]);
  for (int i = 0; i < (n); i++) scanf("%d", &((a)[i]));
  vector<int> lop;
  int ci;
  for (int(i) = 0; (i) < (n); (i)++) {
    ci = upper_bound(lop.begin(), lop.end(), a[i]) - lop.begin();
    if (ci >= int((lop).size()))
      lop.push_back(a[i]);
    else
      lop[ci] = a[i];
  }
  cout << int((lop).size());
  return 0;
}
