#include <bits/stdc++.h>
using namespace std;
long long int INF = 100000023;
int main() {
  int n;
  int a[100000];
  long long int dp[100010];
  cin >> n;
  for (int i = 0; i < (int)(n); i++) cin >> a[i];
  for (int i = 0; i < (int)(n + 1); i++) dp[i] = INF;
  for (int i = 0; i < (int)(n); i++) {
    int j = 0;
    long long int* p = lower_bound(dp, dp + n, a[i]);
    *p = a[i];
  }
  long long int* p = lower_bound(dp, dp + n, INF);
  cout << p - dp << endl;
  return 0;
}
