#include <bits/stdc++.h>
int n, a['   '], *p = a, l['   '], k, i;
int main() {
  for (std::cin >> n; std::cin >> a[i++]; *l = *a)
    for (i = k = 1; i < n; ++i)
      if (l[k - 1] < a[i])
        l[k++] = a[i];
      else
        *std::lower_bound(l, l + k, a[i]) = a[i];
  std::cout << k << "\n";
}
