#include <bits/stdc++.h>
using namespace std;
long long longest(std::vector<long long> v) {
  vector<long long> tail;
  long long i, n = v.size();
  tail.push_back(v[0]);
  for (i = 1; i < n; i++) {
    if (v[i] < tail[0])
      tail[0] = v[i];
    else if (v[i] > tail[tail.size() - 1])
      tail.push_back(v[i]);
    long long x = lower_bound(tail.begin(), tail.end(), v[i]) - tail.begin();
    if (x == tail.size()) continue;
    tail[x] = v[i];
  }
  return tail.size();
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long n, i;
  cin >> n;
  vector<long long> v(n);
  for (i = 0; i < n; i++) cin >> v[i];
  cout << longest(v);
}
