//KZNS
#include <fstream>
using namespace std;
ifstream fin ("lunch.in");
ofstream fout ("lunch.out");
int ls[100003] = {0};
int tl = 0;
int N;
int main() {
fin >> N;
int a;
int l, r;
ls[0] = 0x7fffffff;
for (int i = 0; i < N; i++) {
fin >> a;
if (!a) continue;
if (a < ls[tl]) {
ls[++tl] = a;
continue;
}
l = 0; r = tl;
while (r-l>1) {
if (ls[l+r>>1] > a)
l = l+r>>1;
else
r = l+r>>1;
}
ls[r] = a;
}
fout << tl;
return 0;
}
//UBWH