#include <bits/stdc++.h>
using namespace std;
template <typename T>
T mabs(const T &a) {
  return a < 0 ? -a : a;
}
const int MaxLength = 100500;
int dyn[MaxLength];
int arr[MaxLength];
void run() {
  int n;
  scanf("%d", &n);
  for (int i = (0), ei = (n); i < ei; i++) {
    scanf("%d", &arr[i]);
  }
  vector<int> d(n + 1);
  d[0] = -100500;
  for (int i = 1; i <= n; ++i) d[i] = 100500;
  for (int i = 0; i < n; i++) {
    int j = upper_bound(d.begin(), d.end(), arr[i]) - d.begin();
    if (d[j - 1] < arr[i] && arr[i] < d[j]) d[j] = arr[i];
  }
  int ans = 0;
  for (int i = (0), ei = (n + 1); i < ei; i++) {
    if (d[i] != 100500) ans = i;
  }
  cout << ans << endl;
}
int main() {
  run();
  return 0;
}
