#include <bits/stdc++.h>
using namespace std;
using ui64 = unsigned long long;
using i64 = long long;
const int MAX_N = 100000;
int a[MAX_N];
int L[MAX_N + 1];
int length;
int n;
int compute_lis() {
  L[0] = a[0];
  length = 0;
  for (int i = 1; i < n; ++i) {
    if (L[length - 1] < a[i]) {
      L[length] = a[i];
      length++;
    } else {
      *lower_bound(L, L + length, a[i]) = a[i];
    }
  }
  return length;
}
int main() {
  auto& stream = cin;
  stream >> n;
  for (int i = 0; i < n; ++i) {
    stream >> a[i];
  }
  cout << compute_lis() << endl;
  return 0;
}
