#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int a[MAXN];
int dp[MAXN];
int q[MAXN];
int n;
void cc() {
  int top = 0;
  for (int i = 1; i <= n; i++) {
    if (top == 0 || dp[top] < a[i]) {
      dp[++top] = a[i];
      continue;
    }
    int l = 1, r = top;
    int ans = 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (dp[mid] < a[i])
        l = mid + 1;
      else {
        ans = mid;
        r = mid - 1;
      }
    }
    dp[ans] = a[i];
  }
  cout << top << endl;
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    cc();
  }
  return 0;
}
