#include <bits/stdc++.h>
using namespace std;
long long n, m;
long d[100005];
long a[100005];
bool f = true;
unsigned long long z = 0;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long i = 1; i <= n + 1; i++) {
    d[i] = 110000000;
  }
  d[1] = a[1];
  for (long i = 2; i <= n; i++) {
    long l = 1, r = i;
    if (d[1] > a[i]) {
      d[1] = a[i];
      continue;
    }
    while (l < r) {
      long m = l + (r - l) / 2;
      if (d[m] >= a[i])
        r = m;
      else
        l = m + 1;
    }
    d[r] = a[i];
  }
  for (long i = 1; i <= n + 1; i++) {
    z = i - 1;
    if (d[i] == 110000000) break;
  }
  cout << z;
  return 0;
}
