#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void inp(T &any) {
  cin >> any;
}
template <typename T, typename... U>
inline void inp(T &a, U &...b) {
  cin >> a;
  inp(b...);
}
template <typename T>
inline istream &operator>>(istream &in, vector<T> &a) {
  for (auto &x : a) in >> x;
  return in;
}
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &a) {
  in >> a.first >> a.second;
  return in;
}
long long int LIS(vector<long long int> &a) {
  set<long long int> ms;
  for (auto x : a) {
    ms.emplace(x);
    auto it = ms.upper_bound(x);
    if (it != ms.end()) {
      ms.erase(it);
    }
  }
  return ms.size();
}
void solve(long long int &T) {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  cin >> a;
  cout << LIS(a) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (long long int Case = (1); Case < (t + 1); Case++) {
    if (0) cerr << "Case #" << Case << "\n";
    solve(Case);
  }
  return 0;
}
