#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int dp[100005], INF;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  memset(dp, 63, sizeof(dp)), INF = dp[0];
  dp[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int idx = lower_bound(dp, dp + 1 + n, a[i]) - dp;
    dp[idx] = min(dp[idx], a[i]);
  }
  for (int i = n; i >= 1; --i)
    if (dp[i] != INF) {
      printf("%d", i);
      break;
    }
}
