#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
int newl;
int n;
int main() {
  cin >> n;
  int iii;
  while (n--) {
    cin >> iii;
    arr.push_back(iii);
  }
  int mid = 0;
  newl = 0;
  vector<int> P(n);
  vector<int> M(n - 1);
  int l = 0;
  for (int i = 0; i < (n - 1); i++) {
    int lo = 1;
    int hi = l;
    while (lo <= hi) {
      mid = (lo + hi) / 2;
      if (M[mid] < arr[i]) {
        lo = mid + 1;
      } else {
        hi = mid + 1;
      }
    }
    newl = lo;
    P[i] = M[newl - 1];
    M[newl] = i;
    if (newl > l) {
      l = newl;
    }
  }
  cout << l;
}
