#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6;
int a[maxn], T[maxn * 2], dp[maxn];
int n;
int findMax(int l, int r) {
  l += n - 1;
  r += n - 1;
  int res = 0;
  while (l <= r) {
    if (l & 1) res = max(res, T[l]);
    if (!(r & 1)) res = max(res, T[r]);
    l = (l + 1) >> 1;
    r = (r - 1) >> 1;
  }
  return res;
}
void update(int v, int x) {
  v += n - 1;
  T[v] = max(T[v], x);
  while (v > 1) {
    v >>= 1;
    T[v] = max(T[v + v], T[v + v + 1]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    dp[i] = findMax(1, a[i] - 1) + 1;
    update(a[i], dp[i]);
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}
