#include <bits/stdc++.h>
using namespace std;
int n, m, k, l, idx;
vector<int> a(2, -1);
int main() {
  cin >> n;
  a.back() = 1000000010;
  for (int i = 0; i < n; i++) {
    cin >> m;
    int left = 0, right = a.size() - 1, l;
    while (true) {
      l = (left + right) / 2;
      if (a[l] <= m && m < a[l + 1]) {
        a[l + 1] = m;
        if (l + 2 == a.size()) a.push_back(1000000010);
        break;
      }
      if (a[l] > m)
        right = l;
      else
        left = l + 1;
    }
  }
  cout << a.size() - 2;
  return 0;
}
