#include <bits/stdc++.h>
using namespace std;
enum { WHITE = 0, GRAY, BLACK };
enum { UNVISITED = -1 };
const double pi = 2 * acos(0);
const double tau = 2.0 * pi;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  scanf("%d", &(n));
  static int lis[200005], ans = 0;
  for (int i = 1, ENDD = n; i <= ENDD; i++) {
    int a;
    scanf("%d", &(a));
    int tmp = lower_bound(lis, lis + ans, a) - lis;
    if (tmp == ans)
      lis[ans++] = a;
    else
      lis[tmp] = a;
  }
  printf("%d\n", ans);
  return 0;
}
