12
-6712 6
2375 73
4643 197
-5660 215
-378 223
2228 307
3305 340
3449 468
-4389 707
-7161 729
-1838 921
-1655 985
730
 5
1 5
6 7
17127 17
17072 42
17042 77
3
 7
-976754 20479
79929143 911181
9598220 82517
-51609349 810257
67416551 266544
-14170975 307690
-15476178 491195
352
 22
-5301 602
-1400 194
-8512 987
-282 962
6484 494
9091 523
-7744 92
6002 461
5053 305
-1339 272
-821 165
9308 785
929 421
8384 883
1266 157
8411 923
-2949 885
7725 687
6859 197
-7630 867
5031 918
5662 410
41

11 12
 2 3
 5 5
 9 9

#include <bits/stdc++.h>
using namespace std;
vector<int> dp;
int find(int i, int j, int val) {
  if (i == j) {
    if (val > dp[i])
      return i + 1;
    else
      return i;
  }
  int mid = (i + j) / 2;
  if (val > dp[mid])
    return find(mid + 1, j, val);
  else
    return find(i, mid, val);
}
int main() {
  int a[300000], n, inf = 1e9;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  dp.push_back(a[0]);
  for (int i = 1; i < n; i++) {
    int update = find(0, i - 1, a[i]);
    if (update == dp.size())
      dp.push_back(a[i]);
    else
      dp[update] = a[i];
  }
  printf("%d", dp.size());
}
