#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 12, INF = 1e9 + 7;
int a[N];
int main() {
  int n, m, i, j, k;
  scanf("%d", &(n));
  ;
  vector<int> dp;
  dp.push_back(-100001);
  for (i = 0; i < (n); ++i) {
    dp.push_back(100001);
    scanf("%d", &(a[i]));
    ;
  }
  for (i = 0; i < n; ++i) {
    int j = int(upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin());
    if (dp[j - 1] < a[i] && a[i] < dp[j]) dp[j] = a[i];
  }
  for (i = 1; i <= n; ++i) {
    if (dp[i] == 100001) break;
  }
  cout << i - 1;
}
