1 #include <iostream>
2 #include <cstdio>
3 using namespace std;
4 int len,n;
5 int a[1000000+10],b[1000000+10];
6 int dfen(int x)
7 {
8 int left=0,right=len,mid;
9 while (right-left>0)
10 {
11 mid=(right+left)/2;
12 if (b[mid]==a[x])
13 return 0;
14 if (b[mid]<a[x])
15 left=mid+1;
16 else
17 right=mid;
18 }
19 if (b[left]>a[x])
20 return left;
21 else
22 return 0;
23 }
24 int main()
25 {
26 int i;
27 scanf("%d",&n);
28 for (i=1;i<=n;i++)
29 scanf("%d",&a[i]);
30 b[1]=a[1];
31 len=1;
32 for (i=2;i<=n;i++)
33 if (a[i]>b[len])
34 b[++len]=a[i];
35 else
36 {
37 int pos;
38 pos=dfen(i);
39 if (pos!=0)
40 b[pos]=a[i];
41 }
42 cout<<len;
43 return 0;
44 }