#include <bits/stdc++.h>
using namespace std;
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t) {
  stringstream ss;
  ss << f;
  ss >> t;
}
void mainmain() {
  int n;
  cin >> n;
  srand(time(NULL));
  int m = rand() % 300 + 200;
  vector<int> v;
  for (int(i) = (0); (i) < ((m)); ++(i)) {
    v.push_back(rand() % 1000000000);
  }
  for (int(i) = (0); (i) < ((n)); ++(i)) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  set<pair<int, int> > second;
  second.insert(pair<int, int>(0x3f3f3f3f, 1));
  for (int(i) = (0); (i) < ((n + m)); ++(i)) {
    auto it = second.lower_bound(pair<int, int>(v[i], -i));
    if (it->first != 0x3f3f3f3f) {
      second.erase(it);
    }
    second.insert(min(*it, pair<int, int>(v[i], -i)));
  }
  for (int(i) = (0); (i) < ((m)); ++(i)) {
    auto it = second.find(pair<int, int>(v[i], -i));
    if (it == second.end()) continue;
    second.erase(it);
  }
  cout << second.size() - 1 << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  mainmain();
}
