#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 10, mod = 100000007;
int a[N];
int n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    int val = a[i];
    int pos = lower_bound(ans.begin(), ans.end(), val) - ans.begin();
    if (pos < int(ans.size()))
      ans[pos] = val;
    else
      ans.push_back(val);
  }
  cout << int(ans.size()) << endl;
}
