#include <bits/stdc++.h>
const long double PI = 3.141592653589793238L;
template <typename T = long long>
T next() {
  T result;
  std::cin >> result;
  return result;
}
template <typename T = long long, typename C = std::vector<T>>
C nextv(size_t n) {
  C result(n);
  for (size_t i = 0; i < n; ++i) {
    T temp;
    std::cin >> temp;
    result[i] = temp;
  }
  return result;
}
template <typename T = long long, typename C = std::vector<T>>
C nextv() {
  int n;
  std::cin >> n;
  return nextv<T, C>(n);
}
struct pairhash {
  template <typename T, typename U>
  size_t operator()(const std::pair<T, U>& x) const {
    return std::hash<T>()(x.first) ^ std::hash<U>()(x.second);
  }
};
long long compute_gcd(long long a, long long b) {
  if (b == 0) return a;
  return compute_gcd(b, a % b);
}
unsigned long long compute_lcm(unsigned long long a, unsigned long long b) {
  unsigned long long gcd = compute_gcd(a, b);
  return a / gcd * b;
}
int mod_mul(int a, int b, int mod) { return ((long long)a * b) % mod; }
int mod_add(int a, int b, int mod) { return ((long long)a + b) % mod; }
int mod_pow(int base, int exp, int mod) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = mod_mul(result, base, mod);
    base = mod_mul(base, base, mod);
    exp /= 2;
  }
  return result;
}
long long choose(int n, int k) {
  if (k == 0 || n == 0) return 1;
  long long result = n * choose(n - 1, k - 1) / k;
  return result;
}
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  auto numbers = nextv();
  auto n = numbers.size();
  vector<long long> es(n + 1, INT_MAX);
  es[0] = INT_MIN;
  for (auto number : numbers) {
    long long len = 1;
    auto it = upper_bound(es.begin(), es.end(), number);
    --it;
    len += distance(es.begin(), it);
    es[len] = min(number, es[len]);
  }
  long long result = 0;
  for (size_t i = 0; i < es.size(); ++i) {
    if (es[i] != INT_MAX) result = i;
  }
  cout << result;
  return 0;
}
