#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v;
  v.reserve(n);
  for (long long(i) = 0; (i) < (n); (i)++) {
    int a;
    cin >> a;
    auto itr = lower_bound(v.begin(), v.end(), a);
    if (itr == v.end())
      v.push_back(a);
    else
      *itr = a;
  }
  cout << v.size() << endl;
  return 0;
}
