#include <bits/stdc++.h>
using namespace std;
int n, temp, length, j;
int LAST[100100] = {0};
std::vector<int> A;
int binary_search(int x, int end) {
  int m, s = 0, l = end;
  while (l - s > 1) {
    m = (s + l) / 2;
    if (LAST[m] > x)
      l = m;
    else
      s = m;
  }
  return l;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    A.push_back(temp);
  }
  LAST[0] = A.at(0);
  length = 1;
  for (int i = 1; i < n; i++) {
    if (LAST[length - 1] < A.at(i)) {
      LAST[length] = A.at(i);
      length++;
    } else if (LAST[length - 1] == A.at(i)) {
    } else {
      j = binary_search(A.at(i), length - 1);
      LAST[j] = A.at(i);
    }
  }
  cout << length << endl;
  return 0;
}
