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