#include <bits/stdc++.h>
using namespace std;
int bs(vector<int> &arr, int l, int r, int x) {
  int mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (arr[mid] <= x)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return l;
}
int main() {
  int n;
  cin >> n;
  vector<int> arr(n), lis(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  int l = 1;
  lis[0] = arr[0];
  for (int i = 1; i < n; ++i) {
    if (arr[i] < lis[0])
      lis[0] = arr[i];
    else if (arr[i] > lis[l - 1])
      lis[l++] = arr[i];
    else
      lis[bs(lis, 0, l - 1, arr[i])] = arr[i];
  }
  cout << l;
}
