#include <bits/stdc++.h>
using ll = long long;
template <class T>
constexpr T nil = static_cast<T>(-1);
constexpr int nil_i = nil<int>;
constexpr int nil_ll = nil<ll>;
constexpr double nil_d = nil<double>;
template <class T>
using vec = std::vector<T>;
struct Item {
  int weight, value;
};
void solve() {
  using namespace std;
  constexpr int inf = 1 << 29;
  int n;
  cin >> n;
  vec<int> a(n, 0);
  for (auto& x : a) cin >> x;
  vec<int> dp(n, inf);
  for (int i = 0; i < n; ++i) *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
  cout << distance(dp.begin(), lower_bound(dp.begin(), dp.end(), inf)) << endl;
}
int main() {
  solve();
  return 0;
}
