#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000;
const int INFTY = (1 << 21);
int N;
int a[100000];
int main() {
  cin >> N;
  for (int i = (0); i < (N); i++) cin >> a[i];
  vector<int> vec;
  for (int i = (0); i < (N); i++) {
    if (i == 0)
      vec.push_back(a[i]);
    else {
      if (a[i] > vec[vec.size() - 1]) vec.push_back(a[i]);
      vector<int>::iterator it = upper_bound(vec.begin(), vec.end(), a[i]);
      if (it != vec.end()) *it = a[i];
    }
  }
  cout << vec.size() << endl;
}
