#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
int dp[100003];
int main() {
  int N;
  cin >> N;
  vector<long> a(N);
  fill(dp, dp + N, INF);
  for (long long i = (0); i < (N); ++i) cin >> a[i];
  for (long long i = (0); i < (N); ++i) {
    *lower_bound(dp, dp + N, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp + N, INF) - dp << endl;
  return 0;
}
