#include <bits/stdc++.h>
using namespace std;
long long dp[100010];
int n;
vector<long long> a;
void solve() {
  fill(dp, dp + n, (1 << 20));
  for (int i = 0; i < n; i++) {
    *lower_bound(dp, dp + n, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp + n, (1 << 20)) - dp << endl;
}
int main() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  solve();
  return 0;
}
