#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int a[100010];
int first[100010];
int dp[100010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) first[i] = 0x3f3f3f3f;
  dp[1] = 1;
  first[0] = a[1];
  for (int i = 2; i <= n; i++) {
    int nn = lower_bound(first, first + n, a[i]) - first;
    first[nn] = a[i];
    dp[i] = nn + 1;
  }
  int mn = 0;
  for (int i = 1; i <= n; i++) smax(mn, dp[i]);
  cout << mn << endl;
}
