#include <bits/stdc++.h>
using namespace std;
int L[100005];
int main() {
  int n, a[100005];
  cin >> n;
  for (int(i) = (0); i < (n); i++) cin >> a[i];
  L[0] = a[0];
  int length = 1;
  for (int i = 1; i < n; i++) {
    if (L[length - 1] < a[i]) {
      L[length++] = a[i];
    } else {
      int right = length - 1, left = -1;
      int mid = 0;
      while (left <= right) {
        mid = (right + left) / 2;
        if (L[mid] > a[i]) {
          if (mid == 0) L[mid] = a[i];
        }
        if (L[mid] < a[i])
          left = mid + 1;
        else
          right = mid - 1;
      }
    }
  }
  cout << length << endl;
}
