#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> arr(1e5 + 5);
vector<int> lel(1e5 + 5);
struct cmp {
  bool operator()(int i, int j) const { return arr[i] < arr[j]; }
};
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  arr[n] = 1e9;
  arr[n + 1] = -1e9;
  fill(lel.begin(), lel.end(), n);
  lel[0] = n + 1;
  int res = 0;
  for (int i = 0; i < n; i++) {
    int len = lower_bound(lel.begin(), lel.end(), i, cmp()) - lel.begin();
    lel[len] = i;
    res = max(res, len);
  }
  cout << res;
  return 0;
}
