#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
int pre[100005];
map<int, int>::iterator l, k;
vector<int> LIS_nlogn(vector<int> V) {
  int i, j;
  for (i = 0; i < V.size(); i++) {
    m.insert(make_pair(V[i], i));
    l = k = m.find(V[i]);
    k++;
    if (l == m.begin()) {
      pre[i] = -1;
    } else {
      l--;
      pre[i] = l->second;
    }
    if (k != m.end()) {
      m.erase(k);
    }
  }
  vector<int> res;
  k = m.end();
  res.clear();
  k--;
  j = k->second;
  while (j != -1) {
    res.push_back(j);
    j = pre[j];
  }
  return res;
}
int main() {
  int N, i, x;
  vector<int> V;
  cin >> N;
  for (i = 1; i <= N; i++) {
    cin >> x;
    V.push_back(x);
  }
  vector<int> res = LIS_nlogn(V);
  cout << res.size() << endl;
}
