#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[100000];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int dp[100000];
  for (int i = 0; i < 100000; i++) dp[i] = 1111111111;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    int lb = -1, ub = 99999;
    while (ub - lb > 1) {
      int m = (lb + ub) / 2;
      if (dp[m] < a[i])
        lb = m;
      else
        ub = m;
    }
    dp[ub] = a[i];
    ans = max(ans, ub);
  }
  cout << ans << endl;
  return 0;
}
