#include <bits/stdc++.h>
constexpr int INF = 100100100;
template <typename T>
class Lis {
 public:
  Lis(std::vector<T> const &s, T infty)
      : n(s.size()), inf(infty), seq(s), dp(n, inf) {}
  size_t solve() {
    for (size_t i = 0; i < n; ++i) {
      *std::lower_bound(dp.begin(), dp.end(), seq[i]) = seq[i];
    }
    return std::distance(dp.begin(),
                         std::lower_bound(dp.begin(), dp.end(), inf));
  }

 private:
  size_t const n;
  T const inf;
  std::vector<T> const seq;
  std::vector<T> dp;
};
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  Lis<int> lis(a, INF);
  cout << lis.solve() << endl;
  return 0;
}
