#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int> seq;
const int infty = 1e9 + 10;
int main() {
  int n;
  cin >> n;
  int a[100010];
  for (auto i = 0; i < n; i++) {
    cin >> a[i];
  }
  set<seq> S;
  S.insert(make_tuple(infty, 100010));
  S.insert(make_tuple(-1, 0));
  for (auto i = 0; i < n; i++) {
    auto it = S.lower_bound(make_tuple(a[i], -1));
    it--;
    seq temp = *it;
    get<0>(temp) = a[i];
    ++get<1>(temp);
    S.insert(temp);
  }
  auto it = S.end();
  it--;
  it--;
  int ans = 0;
  while (it != S.begin()) {
    ans = max(ans, get<1>(*it));
    it--;
  }
  cout << ans << endl;
}
