#include <bits/stdc++.h>
using namespace std;
int dp[100100];
int N;
int main() {
  cin >> N;
  for (int i = (0); i < (N + 100); ++i) {
    dp[i] = (1 << 21);
  }
  for (int _ = (0); _ < (N); ++_) {
    int in;
    cin >> in;
    *lower_bound(dp, dp + N, in) = in;
  }
  int cnt = 0;
  for (int i = (0); i < (N); ++i) {
    if (dp[i] < (1 << 21)) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
