#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const int XD = 100100;
int a[XD];
int dp[XD];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  dp[0] = -1;
  for (int i = 1; i <= n; ++i) {
    dp[i] = INF;
  }
  int lim = 1;
  for (int i = 0; i < n; ++i) {
    int lf = 0, rg = lim;
    while (lf < rg) {
      int mid = (lf + rg) >> 1;
      if (a[i] > dp[mid]) {
        lf = mid + 1;
      } else {
        rg = mid;
      }
    }
    dp[lf] = a[i];
    lim = max(lim, lf + 1);
  }
  printf("%d\n", lim - 1);
  return 0;
}
