#include <bits/stdc++.h>
using namespace std;
const int INF = 101001001;
int dp[100010];
int N;
int main() {
  cin >> N;
  fill_n(dp, N + 2, INF);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    int lb = 0, ub = N + 1;
    while (ub - lb > 1) {
      int mid = (ub + lb) / 2;
      if (dp[mid] >= A)
        ub = mid;
      else
        lb = mid;
    }
    dp[ub] = A;
  }
  int lb = 0, ub = N + 1;
  while (ub - lb > 1) {
    int mid = (ub + lb) / 2;
    if (dp[mid] >= INF)
      ub = mid;
    else
      lb = mid;
  }
  cout << ub - 1 << endl;
  return 0;
}
