#include <bits/stdc++.h>
using namespace std;
template <class T>
int CeilIndex(const vector<T>& vec, vector<int>& t, int l, int r, T key) {
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (vec[t[m]] >= key)
      r = m;
    else
      l = m;
  }
  return r;
}
template <class T>
vector<int> LIS(const vector<T>& vec) {
  if (vec.size() == 0) return vector<int>();
  vector<int> tailIndex(vec.size(), 0);
  vector<int> revIndex(vec.size(), -1);
  int len = 1;
  for (int i = 1; i < vec.size(); i++) {
    if (vec[i] < vec[tailIndex[0]]) {
      tailIndex[0] = i;
    } else if (vec[i] > vec[tailIndex[len - 1]]) {
      revIndex[i] = tailIndex[len - 1];
      tailIndex[len++] = i;
    } else {
      int pos = CeilIndex(vec, tailIndex, -1, len - 1, vec[i]);
      revIndex[i] = tailIndex[pos - 1];
      tailIndex[pos] = i;
    }
  }
  vector<int> ans;
  for (int i = tailIndex[len - 1]; i >= 0; i = revIndex[i]) {
    ans.push_back(i);
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a.push_back(t);
  }
  cout << LIS(a).size() << endl;
}
