// AOJ DPL_1_D Longest Increasing Subsequence
// 2018.4.26 bal4u

#include <stdio.h>
#include <stdlib.h>

#define SIZE 100002

int size;      /* the number of data */
int S[SIZE];   /* data array */
int len;       /* the length of LIS */
int L[SIZE];   /* LIS */

int LIS()
{
  int k;
  int lo, hi, mid;

  if (size <= 0) return 0;

  L[0] = S[0];
  len = 1;
  for (k = 1; k < size; k++) {
    if (L[len-1] < S[k]) { L[len++] = S[k]; continue; }
    lo = 0;
    hi = len;
    while (lo < hi) {
      mid = (lo + hi)/2;
      if (L[mid] < S[k]) lo = mid + 1;
      else               hi = mid;
    }
    if (lo < len) L[lo] = S[k];
    else       L[len++] = S[k];
  }
  return len;
}

// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int main()
{
	int i;

	size = in();
	for (i = 0; i < size; i++) S[i] = in();
	printf("%d\n", LIS());
	return 0;
}

