#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  return (b == 0 ? a : gcd(b, a % b));
}
long long x, y, z, n, m, r, l, k, a, h, d;
char c;
vector<int> v;
vector<int> tail;
int bs(int l, int r, int key) {
  while (r - l > 1) {
    int m = l + (r - l) / 2;
    if (tail[m] >= key)
      r = m;
    else
      l = m;
  }
  return r;
}
int dfs() {
  if (v.size() == 0) return 0;
  tail.clear();
  tail.resize(v.size());
  int length = 1;
  tail[0] = v[0];
  for (size_t i = 1; i < v.size(); i++) {
    if (v[i] < tail[0])
      tail[0] = v[i];
    else if (v[i] > tail[length - 1])
      tail[length++] = v[i];
    else
      tail[bs(-1, length - 1, v[i])] = v[i];
  }
  return length;
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x, v.push_back(x);
  cout << dfs();
}
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  solve();
  return 0;
}
