#include <bits/stdc++.h>
using namespace std;
int n;
long long int a[100001];
long long int dp[100001];
int main(void) {
  int i;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    dp[i] = 1000010000;
  }
  for (i = 0; i < n; i++) {
    auto it = lower_bound(dp, dp + n, a[i]);
    *it = a[i];
  }
  int ans = lower_bound(dp, dp + n, 10001000) - dp;
  cout << ans << endl;
  return 0;
}
