#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int leap[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[111111], n;
vector<int>::iterator it;
int lis() {
  vector<int> v;
  v.push_back(-1);
  for (int i = 0; i < n; ++i)
    if (a[i] >= v[v.size() - 1])
      v.push_back(a[i]);
    else {
      it = upper_bound(v.begin(), v.end(), a[i]);
      *it = a[i];
    }
  return v.size() - 1;
}
int main() {
  while (scanf("%d", &n) == 1) {
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    cout << lis() << endl;
  }
  return 0;
}
