#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, a[maxn], par[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> lis;
  lis.push_back(a[0]);
  for (int i = 1; i < n; i++) {
    if (a[i] > lis[lis.size() - 1]) {
      lis.push_back(a[i]);
      par[a[i]] = lis[lis.size() - 2];
      continue;
    }
    int low = lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin();
    lis[low] = a[i];
    if (low == 0)
      par[a[i]] = -1;
    else
      par[a[i]] = lis[low - 1];
  }
  cout << lis.size() << endl;
}
