#include <bits/stdc++.h>
using namespace std;
const int INF = 2034567891;
const long long int INF64 = 1234567890123456789ll;
int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
long long int power(long long int x, long long int y) {
  long long int ans = 1;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % 1000000007;
    x = (x * x) % 1000000007;
    y /= 2;
  }
  return ans;
}
int small[100005], arr[100005], parent[100005], n;
int binary_search(int sz, int value) {
  int low = 0;
  int high = sz - 1;
  int mid;
  while (low < high) {
    mid = low + ((high - low) / 2);
    if (arr[small[mid]] > value)
      high = mid;
    else if (arr[small[mid]] < value)
      low = mid + 1;
    else
      return mid;
  }
  return low;
}
void LIS() {
  int size = 0;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      small[size] = i;
      parent[i] = -1;
    } else if (arr[i] <= arr[small[size]]) {
      int pos = binary_search(size + 1, arr[i]);
      small[pos] = i;
      if (pos != 0) {
        parent[i] = small[pos - 1];
      }
    } else {
      size = size + 1;
      small[size] = i;
      parent[i] = small[size - 1];
    }
  }
  cout << size + 1 << endl;
  int pos = small[size];
  vector<int> v;
  while (size >= 0) {
    v.push_back(arr[pos]);
    pos = parent[pos];
    size--;
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  LIS();
}
