#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int inf = 99999999;
vector<int> lis_fast(const vector<int>& a) {
  const int n = a.size();
  vector<int> A(n, inf);
  vector<int> id(n);
  for (int i = 0; i < n; ++i) {
    id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i]));
    A[id[i]] = a[i];
  }
  int m = *max_element(id.begin(), id.end());
  vector<int> b(m + 1);
  for (int i = n - 1; i >= 0; --i)
    if (id[i] == m) b[m--] = a[i];
  return b;
}
int main() {
  int n;
  cin >> n;
  std::vector<int> v;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  std::vector<int> v1 = lis_fast(v);
  cout << v1.size() << endl;
  return 0;
}
