#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, l, r, res, pos;
int a[maxn], D[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  D[1] = a[1];
  res = 1;
  for (int i = 2; i <= n; i++) {
    if (a[i] >= D[res])
      D[++res] = a[i];
    else {
      l = 1, r = res;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (D[mid] <= a[i])
          l = mid + 1;
        else
          r = mid - 1;
      }
      D[l] = a[i];
    }
  }
  printf("%d", res);
  return 0;
}
