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