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