#include <bits/stdc++.h>
using namespace std;
int a[100002], dp[100001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  fill(dp, dp + n, 1);
  int t = 1;
  for (int i = 1; i < n; i++) {
    int lo = 0, up = t - 1;
    int x = 1;
    while (up >= lo) {
      int d = (up + lo) / 2;
      if (a[d] <= a[i]) {
        if (dp[d] > x - 1) {
          x = dp[d] + 1;
        }
        lo = d + 1;
      } else
        up = d - 1;
    }
    lo = 0;
    up = t - 1;
    bool flag = false;
    while (up >= lo) {
      int d = (up + lo) / 2;
      if (x == dp[d]) {
        a[d] = min(a[i], a[d]);
        flag = true;
        break;
      }
      if (x > dp[d])
        lo = d + 1;
      else
        up = d - 1;
    }
    if (!flag) {
      dp[t] = x;
      a[t++] = a[i];
    }
  }
  int maxIn = 0;
  for (int i = 0; i < n; i++)
    if (dp[i] > dp[maxIn]) maxIn = i;
  cout << dp[maxIn] << endl;
  return 0;
}
