#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[200020], dp[200020], n, maxx = 0, m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    dp[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] > dp[maxx]) {
      maxx++;
      dp[maxx] = a[i];
    } else {
      m = 1;
      while (a[i] > dp[m]) {
        m++;
      }
      if (dp[m] > a[i]) {
        dp[m] = a[i];
      }
    }
  }
  cout << maxx;
  return 0;
}
