#include <bits/stdc++.h>
using namespace std;
inline void fi(int *a) {
  register char c = 0;
  while (c < 33) c = getchar();
  *a = 0;
  while (c > 33) {
    *a = *a * 10 + c - '0';
    c = getchar();
  }
}
int main() {
  int n;
  cin >> n;
  int arr1[n + 2];
  int i, j;
  for (i = 0; i < n; i++) cin >> arr1[i];
  int LIS[n];
  LIS[0] = arr1[0];
  int count = 1;
  for (i = 1; i < n; i++) {
    if (arr1[i] < LIS[0])
      LIS[0] = arr1[i];
    else if (arr1[i] > LIS[count - 1])
      LIS[count++] = arr1[i];
    else {
      int l = 0, r = count - 1, m;
      int idx = r;
      while (r - l > 0) {
        m = (l + r) / 2;
        if (LIS[m] > arr1[i]) {
          r = m;
          idx = r;
        } else if (LIS[m] == arr1[i]) {
          idx = m;
          break;
        } else
          l = m + 1;
        if (m == l) break;
      }
      LIS[idx] = arr1[i];
    }
  }
  printf("%d\n", count);
  return 0;
}
