#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 29;
const double dinf = 1e30;
const long long linf = 1LL << 55;
const int N = 111111;
int rec[N];
int a[N], n;
int bs(int pos, int x) {
  int l = 0, r = pos;
  int res;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (a[rec[mid]] < x)
      res = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  return res;
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    rec[0] = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      int res = bs(ans, a[i]);
      if (res == ans) ans++;
      rec[res + 1] = i;
    }
    cout << ans << endl;
  }
  return 0;
}
