#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long inf = LLONG_MAX;
long double pi = 3.1415926536;
int ans(std::vector<int>& v) {
  if (v.size() == 0) return 0;
  std::vector<int> tail(v.size(), 0);
  int length = 1;
  tail[0] = v[0];
  for (int i = 1; i < v.size(); i++) {
    auto b = tail.begin(), e = tail.begin() + length;
    auto it = lower_bound(b, e, v[i]);
    if (it == tail.begin() + length)
      tail[length++] = v[i];
    else
      *it = v[i];
  }
  return length;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt = 1;
  while (tt--) {
    long long n, x = 0, m = 0, y = 0, k = inf;
    cin >> n;
    vector<int> v(n, 0);
    for (long long i = 0; i < n; i++) {
      cin >> x;
      v[i] = x;
    }
    cout << ans(v) << '\n';
  }
}
