#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 100000 + 1;
int n;
int a[N_MAX];
bool input() {
  if (cin >> n) {
    for (int i = 0; i < n; ++i) cin >> a[i];
    return true;
  }
  return false;
}
int solve() {
  int l[n];
  int lc = 1;
  l[0] = a[0];
  for (int i = 0; i < n; ++i) {
    if (l[lc - 1] < a[i]) l[lc++] = a[i];
    auto it = upper_bound(l, l + lc, a[i]);
    if (it != l + lc) *it = a[i];
  }
  return lc;
}
int main() {
  while (input()) {
    cout << solve() << endl;
  }
  return 0;
}
