#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
int n, a[100005], h[100005];
int main() {
  int ans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    h[i + 1] = INF;
    int lo = 0, hi = i;
    while (lo < hi) {
      int m = (lo + hi + 1) / 2;
      if (a[i] > h[m])
        lo = m;
      else
        hi = m - 1;
    }
    ans = max(ans, ++lo);
    h[lo] = a[i];
  }
  printf("%d\n", ans);
  if (0) {
    int b[10];
    for (int i = 0; i < n; i++) a[i] = i;
    do {
      set<int> e[200];
      for (int i = 0; i < n; i++) b[i] = a[i];
      bool ok = true;
      while (ok) {
        ok = false;
        for (int i = 1; i < n; i++) {
          if (b[i - 1] > b[i]) {
            ok = true;
            e[b[i - 1]].insert(b[i]);
            e[b[i]].insert(b[i - 1]);
            swap(b[i - 1], b[i]);
          }
        }
      }
      int mask = (1 << n) - 1, ans = 0, tag = 0;
      for (int s = 0; s <= mask; s++) {
        ok = true;
        int cnt = __builtin_popcount(s);
        if (cnt <= ans) continue;
        for (int i = 0; i < n; i++)
          if (s & 1 << i)
            for (int j = 0; j < i; j++)
              if (s & 1 << j)
                if (e[i].count(j) || e[j].count(i)) i = j = n, ok = false;
        if (ok) {
          ans = cnt;
          tag = s;
        }
      }
      printf("result = %d for list", ans);
      for (int i = 0; i < n; i++) printf(" %d", a[i]);
      printf(", set =");
      for (int i = 0; i < n; i++)
        if (tag & 1 << i) printf(" %d", i);
      puts("");
    } while (next_permutation(a, a + n));
  }
}
