#include <bits/stdc++.h>
using namespace std;
int n, a[100005], d[100005];
int f(int s, int q) {
  int l, r, m, ans;
  l = 1;
  r = s;
  while (l <= r) {
    m = (l + r) >> 1;
    if (d[m] > q) {
      ans = m;
      r = m - 1;
    } else {
      l = m + 1;
    }
  }
  return ans;
}
int lis(void) {
  int ans, i, x;
  ans = 1;
  d[1] = a[1];
  for (i = 2; i <= n; i++) {
    if (a[i] < d[1])
      d[1] = a[i];
    else if (a[i] > d[ans])
      d[++ans] = a[i];
    else {
      x = f(ans, a[i]);
      d[x] = a[i];
    }
  }
  return ans;
}
int main() {
  int i;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  cout << lis() << endl;
  return 0;
}
