#include <bits/stdc++.h>
using namespace std;
int dy[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
struct S {
  int a, b, c;
};
bool asc(const S& left, const S& right) { return left.c > right.c; }
int n, m, l, r;
vector<int> a;
int dp[100001];
void input() {
  cin >> n;
  int tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    a.push_back(tmp);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  int ans = 0, tmp = 0;
  for (int i = 0; i < n; i++) dp[i] = 1 << 25;
  for (int i = 0; i < n; i++) {
    *lower_bound(dp, dp + n, a[i]) = a[i];
  }
  cout << (lower_bound(dp, dp + n, 1 << 25) - dp) << endl;
  return 0;
}
