#include <bits/stdc++.h>
using namespace std;
int N;
int a[100005];
int dp[100005];
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  cout << a[0];
  fill(dp, dp + N, (1 << 30));
  for (int i = 0; i < N; i++) {
    *lower_bound(dp, dp + N, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp + N, (1 << 30)) - dp << endl;
}
