#include <stdio.h>
#include <stdlib.h>
Node* nodes[200001] = {0};
typedef struct NodeStruct {
int value;
NodeStruct* next;
} Node;
Node* CreateNewRootNode(Node* next, int value) {
Node* node = malloc(sizeof(Node));
node->value = value;
node->next = next;
return node;
}
int main() {
int n;
scanf("%d", &n);
int* numbers = calloc(n, sizeof(int));
for (int i = 0; i < n; i++) {
scanf("%d", &numbers[i]);
if (nodes[numbers[i]] == NULL) {
nodes[numbers[i]] = CreateNewRootNode(NULL, i);
} else {
nodes[numbers[i]] = CreateNewRootNode(nodes[numbers[i]], i);
}
}
int subseqMaxLen = 1;
int* subseqStart = calloc(n + 1, sizeof(int));
subseqStart[0] = 200001;
subseqStart[1] = numbers[n - 1];
for (int i = n - 2; i >= 0; i--) {
if (numbers[i] < subseqStart[subseqMaxLen]) {
subseqStart[++subseqMaxLen] = numbers[i];
continue;
}
for (int j = subseqMaxLen - 1; j >= 0; j--) {
if (numbers[i] < subseqStart[j] && numbers[i] > subseqStart[j + 1]) {
subseqStart[j + 1] = numbers[i];
}
}
}
free(numbers);
free(subseqStart);
printf("%d", subseqMaxLen);
return 0;
}