#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> dp(100001);
  for (int i = 0; i < n + 1; i++) dp[i] = 999999999;
  for (int i = 0; i < n; i++)
    *lower_bound(dp.begin(), dp.begin() + n, a[i]) = a[i];
  cout << lower_bound(dp.begin(), dp.begin() + n, 999999999) - dp.begin()
       << endl;
  return 0;
}
