#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, m, n;
  cin >> n;
  vector<int> d(n);
  vector<int> g(n);
  for (i = 0; i < n; ++i) {
    cin >> d[i];
  }
  g[0] = d[0];
  int l, r, len = 1;
  for (i = 1; i < n; ++i) {
    l = 0;
    r = len;
    while (l < r) {
      int m = l + (r - l) / 2;
      if (d[i] < g[m])
        r = m;
      else if (d[i] == g[m])
        l = m;
      else
        l = m + 1;
    }
    if (l == len) len++;
    g[l] = d[i];
  }
  cout << len << endl;
  return 0;
}
