#include <bits/stdc++.h>
using namespace std;
long long n, a[100005], lis[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long len = 0;
  for (long long i = 0; i < n; i++) {
    long long pos = lower_bound(lis, lis + len, a[i]) - lis;
    lis[pos] = a[i];
    if (pos + 1 > len) len = pos + 1;
  }
  cout << len << endl;
  return 0;
}
