#include <bits/stdc++.h>
using namespace std;
int a[100000];
int dp[100000];
int search(int key, int n) {
  int left = 0;
  int right = n;
  while (left < right) {
    int mid = (left + right) / 2;
    if (dp[mid] < key) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  return left - 1;
}
void solve(int n) {
  int length = 0;
  dp[0] = a[0];
  for (int i = 1; i < n; i++) {
    if (dp[length - 1] < a[i]) {
      dp[length++] = a[i];
    } else {
      int index = search(a[i], n);
      dp[index] = a[i];
    }
  }
  cout << length << endl;
}
void init() {
  for (int i = 0; i < 100000; i++) {
    dp[i] = 0;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  init();
  solve(n);
}
