#include <bits/stdc++.h>
using namespace std;
int a[100001];
int b[100001], *pb = b + 1;
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i != n; ++i) scanf("%d", a + i);
  *pb++ = a[0];
  for (int i = 1; i != n; ++i) {
    if (a[i] > pb[-1])
      *pb++ = a[i];
    else {
      int *p1 = b, *p2 = pb, *mid = b;
      while (p1 <= p2) {
        mid = p1 + (p2 - p1) / 2;
        if (*mid < a[i] && a[i] <= mid[1])
          break;
        else if (a[i] < *mid)
          p2 = mid - 1;
        else
          p1 = mid + 1;
      }
      mid[1] = a[i];
    }
  }
  printf("%d\n", pb - b - 1);
  return 0;
}
