#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int increasingSubsequece2(int a[], int n) {
  vector<int> temp;
  vector<int>::iterator v;
  temp.push_back(a[0]);
  for (int i = 1; i < n; ++i) {
    if (a[i] > temp.back())
      temp.push_back(a[i]);
    else {
      v = upper_bound(temp.begin(), temp.end(), a[i]);
      *v = a[i];
    }
  }
  return temp.size();
}
int bit[1000005] = {0};
void update(int i, int val) {
  while (i < 1000005) {
    bit[i] = max(bit[i], val);
    i += (i & (-i));
  }
}
int query(int i) {
  int ans = 0;
  while (i > 0) {
    ans = max(ans, bit[i]);
    i -= (i & -i);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << increasingSubsequece2(a, n) << '\n';
  return 0;
}
