#include <bits/stdc++.h>
using namespace std;
int n, arr[100005];
vector<int> v;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    int pos = upper_bound(v.begin(), v.end(), arr[i]) - v.begin();
    if (pos == v.size())
      v.push_back(arr[i]);
    else
      v[pos] = arr[i];
  }
  cout << v.size() << endl;
}
