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