#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 10;
int n, dp[maxn], a[maxn];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0;
  memset(dp, INF, sizeof(dp));
  for (int i = 0; i < n; i++) {
    int pos = lower_bound(dp, dp + n, a[i]) - dp;
    dp[pos] = a[i];
    ans = max(ans, pos + 1);
  }
  cout << ans << endl;
  return 0;
}
