#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> d;
  for (int i = 0; i < n; ++i) {
    int pos = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
    if (pos == d.size())
      d.push_back(a[i]);
    else
      d[pos] = a[i];
  }
  cout << d.size();
}
