#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF = 0x7f7f7f7f;
int n;
int a[MAXN];
int dp[MAXN];
int main() {
  scanf("%d", &n);
  for (int ii = 1; ii <= n; ii++) {
    scanf("%d", &a[ii]);
  }
  memset(dp, 0x7f, sizeof(dp));
  dp[1] = a[1];
  for (int ii = 2; ii <= n; ii++) {
    int l = 1, r = ii - 1, lstp = -1;
    while (l <= r) {
      int mid = l + (r - l) / 2;
      if (dp[mid] <= a[ii]) {
        lstp = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    if (lstp == -1)
      dp[1] = min(dp[1], a[ii]);
    else {
      dp[lstp + 1] = min(dp[lstp + 1], a[ii]);
    }
  }
  for (int ii = n; ii >= 1; ii--) {
    if (dp[ii] != INF) {
      cout << ii << endl;
      break;
    }
  }
}
