#include <bits/stdc++.h>
using namespace std;
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
struct Order {
  bool operator()(pair<long long, long long> const& a,
                  pair<long long, long long> const& b) const {
    return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
  }
};
int main(void) {
  long N, l, r, mid, idx;
  cin >> N;
  vector<long long> dp(N + 1, loINF);
  dp[0] = (-1);
  vector<long long> a(N);
  for (long long i = 0; i < (N); i++) cin >> a[i];
  for (long long i = 0; i < (N); i++) {
    idx = (lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin());
    dp[idx] = min(dp[idx], a[i]);
  }
  for (long long i = 0; i < (N + 1); i++) {
    if (dp[i] == loINF || i == (N)) {
      cout << (i) << endl;
      break;
    }
  }
}
