#include <bits/stdc++.h>
using namespace std;
int f(vector<int>& v) {
  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;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<int> ar(n);
  long long mx = 0;
  for (long long i = 0; i < (long long)n; ++i) {
    cin >> ar[i];
  }
  cout << f(ar) << endl;
}
