#include <bits/stdc++.h>
using namespace std;
const int max_n = 2e5 + 10;
int n, temp;
vector<int> ans;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    int pos = lower_bound(ans.begin(), ans.end(), temp) - ans.begin();
    if (pos == ans.size())
      ans.push_back(temp);
    else
      ans[pos] = temp;
  }
  cout << ans.size() << endl;
  return 0;
}
