#include <bits/stdc++.h>
using namespace std;
static const long long MAX_N = 1ll << 17;
long long dat[2 * MAX_N - 1];
class Segment {
 public:
  long long n;
  void inti(long long n_) {
    n = 1;
    while (n < n_) n *= 2;
    for (long long i = 0; i < 2 * n - 1; ++i) dat[i] = -INT_MAX;
  }
  void update(long long k, long long a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  long long query(long long a, long long b, long long k, long long l,
                  long long r) {
    if (a <= l && r <= b) return dat[k];
    if (r <= a || b <= l)
      return -INT_MAX;
    else {
      long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return max(vl, vr);
    }
  }
};
long long N;
long long A[MAX_N];
signed main() {
  cin >> N;
  Segment seg;
  seg.inti(N);
  for (long long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (long long i = 0; i < N; ++i) {
    long long j = A[i];
    seg.update(j, 1);
    seg.update(j, max(dat[j + seg.n - 1], seg.query(0, j, 0, 0, seg.n) + 1));
  }
  cout << dat[0] << endl;
  return 0;
}
