#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
int n;
int Sequence[100010];
int L[100010];
int I[100010];
void takeInput() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &Sequence[i]);
}
int LisNlogK() {
  int i;
  I[0] = -inf;
  for (i = 1; i <= n; i++) I[i] = inf;
  int LisLength = 0;
  for (i = 0; i < n; i++) {
    int low, high, mid;
    low = 0;
    high = LisLength;
    while (low <= high) {
      mid = (low + high) / 2;
      if (I[mid] < Sequence[i])
        low = mid + 1;
      else
        high = mid - 1;
    }
    I[low] = Sequence[i];
    if (LisLength < low) LisLength = low;
  }
  return LisLength;
}
int main() {
  takeInput();
  int result = LisNlogK();
  cout << result << endl;
  return 0;
}
