#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int main() {
  int i, j, n, top, tmp;
  int stack[maxn];
  cin >> n;
  top = 0;
  stack[0] = 0;
  for (i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp > stack[top]) {
      stack[++top] = tmp;
    } else {
      int low = 1, high = top;
      int mid;
      while (low <= high) {
        mid = (low + high) / 2;
        if (tmp > stack[mid]) {
          low = mid + 1;
        } else {
          high = mid - 1;
        }
      }
      stack[low] = tmp;
    }
  }
  cout << top << endl;
  return 0;
}
