#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main() {
  int n, i, elem;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n + 1, INF);
  for (i = 0; i < n; ++i) {
    cin >> elem;
    *upper_bound(B.begin(), B.end(), elem) = elem;
  }
  int ans = 0;
  for (i = 0; i < n; ++i)
    if (B[i] < INF) ans++;
  cout << ans << endl;
  return 0;
}
