#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 9;
ifstream Cin("input.txt");
ofstream Cout("output.txt");
int main() {
  long long n, i, k, l = 0, dp[100001] = {}, ans = 0;
  cin >> n;
  vector<long long> r(n + 1);
  for (i = 1; i <= n; ++i) cin >> r[i];
  for (i = 0; i < 100001; ++i) dp[i] = INF;
  dp[0] = -INF;
  for (i = 1; i <= n; ++i) {
    long long ll = 0, rr = 100000, mm;
    while (ll + 1 < rr) {
      mm = (ll + rr) / 2;
      if (dp[mm] <= r[i])
        ll = mm;
      else
        rr = mm - 1;
    }
    if (dp[rr] <= r[i]) ll = rr;
    dp[ll + 1] = r[i];
    ans = max(ans, ll + 1);
  }
  cout << ans;
}
