#include <bits/stdc++.h>
using namespace std;
const long long INFx = 1e16;
const pair<long long, long long> INF = pair<long long, long long>(INFx, INFx);
long long lis(vector<pair<long long, long long> > const& a) {
  long long n = a.size();
  vector<pair<long long, long long> > d(n + 1, INF);
  d[0] = pair<long long, long long>(-INFx, -INFx);
  for (long long i = 0; i < n; i++) {
    long long j = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
    if (d[j - 1] < a[i] && a[i] < d[j]) d[j] = a[i];
  }
  long long ans = 0;
  for (long long i = 0; i <= n; i++)
    if (d[i] < INF) ans = i;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<pair<long long, long long> > myvec(n), sol;
  for (long long i = 0; i < n; i++) {
    cin >> myvec[i].first;
    myvec[i].second = i;
  }
  cout << lis(myvec) << endl;
  return 0;
}
