#include <bits/stdc++.h>
using namespace std;
double PI = 4.00 * (atan(1));
long long int ceilfind(long long int endlen[], long long int start,
                       long long int end, long long int key) {
  long long int mid;
  while ((end - start) > 1) {
    mid = (end + start) / 2;
    if (endlen[mid] >= key) {
      end = mid;
    } else {
      start = mid;
    }
  }
  return end;
}
long long int LIS(long long int arr1[], long long int n) {
  long long int endpos[n];
  for (long long int i = 1; i < n; i++) {
    endpos[i] = -1;
  }
  endpos[0] = arr1[0];
  long long int currend = 0;
  for (long long int i = 1; i < n; i++) {
    if (arr1[i] < endpos[0]) {
      endpos[0] = arr1[i];
      continue;
    }
    if (arr1[i] > endpos[currend]) {
      currend++;
      endpos[currend] = arr1[i];
      continue;
    }
    long long int val1 = ceilfind(endpos, -1, currend, arr1[i]);
    endpos[val1] = arr1[i];
  }
  return currend + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int arr1[n];
  for (long long int i = 0; i < n; i++) {
    cin >> arr1[i];
  }
  long long int ans = LIS(arr1, n);
  cout << ans;
  return 0;
}
