#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 100;
int n, last, a[maxN], BIS[maxN];
void input() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
}
int find(int l, int r, int key) {
  int now = (r + l) / 2;
  if ((r - l == 1 && BIS[r] > key && BIS[r - 1] <= key))
    return r;
  else if (r - l == 1 && BIS[l] > key && BIS[l - 1] <= key)
    return l;
  else if (r == l && BIS[r] > key && BIS[r - 1] <= key)
    return r;
  else if (r - l == 1)
    return 0;
  else if (r == l)
    return 0;
  if (BIS[now] > key && BIS[now - 1] <= key)
    return now;
  else if (BIS[now] < key)
    return find(now + 1, r, key);
  else
    return find(l, now - 1, key);
  return 0;
}
int main() {
  input();
  last = 1;
  BIS[1] = a[1];
  for (int i = 2; i <= n; i++) {
    BIS[0] = 0;
    if (a[i] > BIS[last]) {
      last++;
      BIS[last] = a[i];
    }
    BIS[find(1, last, a[i])] = a[i];
  }
  cout << last << endl;
  return 0;
}
