#include <bits/stdc++.h>
using namespace std;
int a[100010] = {0};
int b[100010] = {0};
int getpos(int lst[], int start, int end, int val) {
  int mid = 0;
  while (start < end - 1) {
    mid = (start + end) >> 1;
    if (lst[mid] >= val) {
      end = mid - 1;
    } else {
      start = mid;
    }
  }
  mid = (start + end) >> 1;
  while (mid <= end && lst[mid] < val) {
    mid++;
  }
  while (mid > end || lst[mid] >= val) {
    mid--;
  }
  return mid + 1;
}
int main() {
  int n = 0, k = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] > b[k]) {
      k++;
      b[k] = a[i];
    } else {
      int pos = getpos(b, 1, k, a[i]);
      b[pos] = a[i];
    }
  }
  cout << k << endl;
  return 0;
}
