#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
const int INF = INT_MAX / 3;
int main() {
  int n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < (int)n; ++i) cin >> a[i];
  long long b[n];
  for (int i = 0; i < (int)n; ++i) b[i] = INF;
  for (int i = 0; i < (int)n; ++i) {
    *lower_bound(b, b + n, a[i]) = a[i];
  }
  cout << lower_bound(b, b + n, INF) - b << endl;
  return 0;
}
