#include <bits/stdc++.h>
using namespace std;
int a[100500];
int v[100500];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  v[0] = -1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int l = 0, r = ans + 1;
    while (r - l > 1) {
      int j = (l + r) / 2;
      if (v[j] < a[i])
        l = j;
      else
        r = j;
    }
    v[l + 1] = a[i];
    if (l + 1 > ans) ans = l + 1;
  }
  cout << ans;
  return 0;
}
