#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e10, EPS = 1e-9;
template <class T>
int SIZE(T a) {
  return a.size();
}
template <class T>
string IntToString(T num) {
  string res;
  stringstream ss;
  ss << num;
  return ss.str();
}
template <class T>
T StringToInt(string str) {
  T res = 0;
  for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] - '0');
  return res;
}
template <class T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
void input(T& a, int n) {
  for (int i = 0; i < n; ++i) cin >> a[i];
}
template <class T>
void input(T* a, int n) {
  for (int i = 0; i < n; ++i) cin >> a[i];
}
int chmax(int& a, int b) {
  if (b > a) {
    a = b;
  }
  return a;
}
int chmin(int& a, int b) {
  if (b < a) {
    a = b;
  }
  return a;
}
int dp[100000 + 10] = {0};
int d[100000 + 10] = {0};
int main() {
  int N;
  cin >> N;
  fill(dp, dp + N, inf);
  for (int f = 0; f < (int)N; f++) {
    cin >> d[f];
    *lower_bound(dp, dp + N, d[f]) = d[f];
  }
  cout << lower_bound(dp, dp + N, inf) - dp << endl;
  return 0;
}
