#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N + 1];
  int L[N + 1];
  for (int i = 1; i < N + 1; ++i) {
    cin >> A[i];
  }
  L[1] = A[1];
  int length = 1;
  for (int i = 2; i < N + 1; ++i) {
    if (L[length] < A[i])
      L[++length] = A[i];
    else if (A[i] < L[1])
      L[1] = A[i];
    else {
      int k = (length + 1) / 2, s = (k + 1) / 2;
      while (k > 0 && k < length + 1) {
        if (A[i] == L[k] || A[i] == L[k + 1])
          break;
        else if (A[i] < L[k + 1] && L[k] < A[i]) {
          L[k + 1] = A[i];
          break;
        } else if (A[i] < L[k])
          k -= s;
        else if (A[i] > L[k + 1])
          k += s;
        s = (s + 1) / 2;
      }
    }
  }
  cout << length << endl;
}
