#include <bits/stdc++.h>
int ceilindex(int sec_array[], int l, int r, int key) {
  while (r - l >= 1) {
    int m = l + r / 2;
    if (sec_array[m] >= key)
      r = m;
    else
      l = m;
  }
  return r;
}
int findNumberOfLIS(int nums[], int n) {
  int sec_array[n];
  int len;
  sec_array[0] = nums[0];
  len = 1;
  for (int i = 1; i < n; i++) {
    if (nums[i] < sec_array[0])
      sec_array[0] = nums[i];
    else if (nums[i] > sec_array[len - 1])
      sec_array[len++] = nums[i];
    else {
      sec_array[ceilindex(sec_array, 0, len - 1, nums[i])] = nums[i];
    }
  }
  return len;
}
int main() {
  int n;
  scanf("%d", &n);
  int nums[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &nums[i]);
  }
  printf("%d\n", findNumberOfLIS(nums, n));
  return 0;
}
