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