#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int a[1000000];
int n;
int dp[1000000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i <= n; i++) {
    dp[i] = inf;
  }
  for (int i = 0; i < n; i++) {
    int k = upper_bound(dp, dp + n + 1, a[i]) - dp;
    dp[k] = a[i];
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (dp[i] != inf) {
      ans = i + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
