#include <bits/stdc++.h>
using namespace std;
int find(vector<int> r, int a) {
  int left = 0, right = r.size();
  while (right - left > 1) {
    int mid = (left + right) / 2;
    if (r[mid] <= a)
      left = mid;
    else
      right = mid;
  }
  return left;
}
int main() {
  int n;
  cin >> n;
  int a[100001];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> result;
  for (int i = 0; i < n; i++) {
    int l = result.size();
    if (l == 0 || result[l - 1] < a[i]) {
      result.push_back(a[i]);
    } else {
      int tmp = find(result, a[i]);
      result[tmp] = a[i];
    }
  }
  cout << result.size() << endl;
  return 0;
}
