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