#include <bits/stdc++.h>
using namespace std;
int arr[100100], N;
int solve() {
  vector<int> v;
  for (int i = 0; i < N; i++) {
    vector<int>::iterator it = upper_bound(v.begin(), v.end(), arr[i]);
    if (it == v.end())
      v.push_back(arr[i]);
    else
      *it = arr[i];
  }
  return v.size();
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> arr[i];
  cout << solve() << '\n';
  return 0;
}
