#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  vector<long long> v;
  for (int i = 1; i <= N; i++) {
    long long tmp;
    cin >> tmp;
    int idx = lower_bound(v.begin(), v.end(), tmp) - v.begin();
    if (idx == v.size()) {
      v.push_back(tmp);
    } else {
      v[idx] = tmp;
    }
  }
  cout << v.size() << '\n';
}
