#include <bits/stdc++.h>
using namespace std;
int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
vector<string> form(string a, char s) {
  a += s;
  vector<string> v;
  string b;
  for (int i = (0); i < (int)(a.size()); ++i) {
    if (a[i] == s) {
      v.push_back(b);
      b = "";
    } else
      b += a[i];
  }
  return v;
}
vector<int> formint(string a, char s) {
  vector<int> v;
  vector<string> w = form(a, s);
  for (int i = (0); i < (int)(w.size()); ++i) v.push_back(toInt(w[i]));
  return v;
}
const int inf = 99999999;
int lis_fast(const vector<int>& a) {
  const int n = a.size();
  vector<int> A(n, inf);
  vector<int> id(n);
  for (int i = 0; i < n; ++i) {
    id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i]));
    A[id[i]] = a[i];
  }
  int m = *max_element(id.begin(), id.end());
  return m + 1;
}
int main(void) {
  int n;
  scanf("%d", &n);
  vector<int> v(n);
  for (int i = (0); i < (int)(n); ++i) cin >> v[i];
  int res = lis_fast(v);
  cout << res << endl;
  return 0;
}
