#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int> vec(N, 0);
  vector<int> dp(N, (1 << 30));
  for (int i = 0; i < N; i++) cin >> vec[i];
  for (int i = 0; i < N; i++) {
    auto lb = lower_bound(dp.begin(), dp.end(), vec[i]);
    if (*lb == (1 << 30) || *(lb + 1) == (1 << 30)) *lb = vec[i];
  }
  cout << lower_bound(dp.begin(), dp.end(), (1 << 30)) - dp.begin() << endl;
  return 0;
}
