#include <bits/stdc++.h>
using namespace std;
vector<int> d, a;
int n, t;
int main() {
  cin >> n;
  while (n--) cin >> t, a.push_back(t);
  for (auto i : a)
    if (lower_bound(d.begin(), d.end(), i) == d.end())
      d.push_back(i);
    else
      *lower_bound(d.begin(), d.end(), i) = i;
  cout << d.size();
}
