#include <bits/stdc++.h>
using namespace std;
long binarySearch(long x, long s, long L, vector<long> &X, vector<long> &M) {
  if (s == L - 1) {
    if (X[M[s]] < x)
      return s;
    else
      return -1;
  }
  if (X[M[(L + s) / 2]] <= x)
    return binarySearch(x, (L + s) / 2, L, X, M);
  else
    return binarySearch(x, s, (L + s) / 2, X, M);
  return -1;
}
int main() {
  long n;
  cin >> n;
  vector<long> X(n), P(n, -1), M(n, -1);
  long L = 0;
  for (int i = 0; i < n; i++) {
    cin >> X[i];
    long j = L - 1;
    if (L) j = binarySearch(X[i], 0, L, X, M);
    if (j == L - 1) {
      L++;
      M[L - 1] = i;
    } else if (X[i] < X[M[j + 1]])
      M[j + 1] = i;
  }
  cout << L << endl;
}
