#include <bits/stdc++.h>
using namespace std;
const double pi = 4 * atan(1.0);
int mod = 1000000007;
int main() {
  int N;
  cin >> N;
  vector<int> arr(N);
  for (auto& val : arr) cin >> val;
  vector<int> dp(N);
  int ans = 0;
  dp[0] = arr[0];
  for (int i = 1; i < N; ++i) {
    if (arr[i] > dp[ans]) {
      dp[++ans] = arr[i];
    } else {
      int min = 0, max = ans;
      int mid;
      while (1) {
        mid = (max - min) / 2 + min;
        if (min == mid) {
          if (min == 0) {
            if (dp[0] >= arr[i]) {
              mid = min;
            } else {
              mid = -1;
            }
          }
          break;
        }
        if (dp[mid] > arr[i]) {
          max = mid;
        } else if (dp[mid] < arr[i]) {
          min = mid;
        } else {
          break;
        }
      }
      if (mid >= 0) dp[mid] = arr[i];
    }
  }
  cout << ans + 1 << endl;
  return 0;
}
