#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, x;
  cin >> n;
  long long int ar[n], ans = 0;
  vector<long long int> temp;
  for (long long int i = 0; i < n; i++) {
    cin >> ar[i];
    auto it = upper_bound(temp.begin(), temp.end(), ar[i]);
    if (it == temp.end())
      temp.push_back(ar[i]);
    else
      *it = ar[i];
  }
  cout << temp.size();
}
