#include <bits/stdc++.h>
using namespace std;
const long long fx[] = {+1, -1, +0, +0};
const long long fy[] = {+0, +0, +1, -1};
const long long N = 1e6 + 5, K = 20, mod = 1000000007, MOD = 1000000007,
                INF = LLONG_MAX / 2;
long long CeilIndex(std::vector<long long>& v, long long l, long long r,
                    long long key) {
  while (r - l > 1) {
    long long m = l + (r - l) / 2;
    if (v[m] >= key)
      r = m;
    else
      l = m;
  }
  return r;
}
long long LongestIncreasingSubsequenceLength(std::vector<long long>& v) {
  if (v.size() == 0) return 0;
  std::vector<long long> tail(v.size(), 0);
  long long length = 1;
  tail[0] = v[0];
  for (size_t i = 1; i < v.size(); i++) {
    if (v[i] < tail[0])
      tail[0] = v[i];
    else if (v[i] > tail[length - 1])
      tail[length++] = v[i];
    else
      tail[CeilIndex(tail, -1, length - 1, v[i])] = v[i];
  }
  return length;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  cout << LongestIncreasingSubsequenceLength(v) << endl;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long TESTS = 1;
  while (TESTS--) {
    solve();
  }
  return 0;
}
