#include <bits/stdc++.h>
using namespace std;
int main() {
  ifstream fin("in.txt");
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  int n;
  fin >> n;
  int a[n];
  for (int i = 0; i < n; i++) fin >> a[i];
  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];
  }
  cout << lower_bound(dp, dp + n, INT_MAX) - dp << endl;
  end = chrono::system_clock::now();
  double elapsed =
      chrono::duration_cast<chrono::milliseconds>(end - start).count();
  return 0;
}
