#include <bits/stdc++.h>
using namespace std;
int f[101000], dp[101000], a[101000];
int n;
int tot;
int find(int x) {
  int l = 0, r = tot;
  int ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (f[mid] <= x) {
      ans = max(mid, ans);
      l = mid + 1;
    } else
      r = mid - 1;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int(i) = 0; (i) < (n); (i)++) scanf("%d", &a[i]);
  memset(dp, 0, sizeof(dp));
  tot = 0;
  for (int i = 0; i < n; i++) {
    int j = find(a[i]);
    dp[i] = j + 1;
    if (j + 1 > tot) {
      tot++;
      f[j + 1] = a[i];
    } else
      f[j + 1] = min(f[j + 1], a[i]);
  }
  int ans = 0;
  for (int(i) = 0; (i) < (n); (i)++) ans = max(ans, dp[i]);
  printf("%d\n", ans);
  return 0;
}
