#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 1;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  vector<int> dp(n, INF);
  for (int i = 0; i < n; i++) {
    *lower_bound(begin(dp), end(dp), a[i]) = a[i];
  }

  int ans = distance(begin(dp), lower_bound(begin(dp), end(dp), INF));
  cout << ans << endl;

  return 0;
}

