http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1134&judgeId=529543
/*
input:
8
5 1 6 8 2 4 5 10
output:
5
*/
#include"bits/stdc++.h"
using namespace std;
const int maxn=1e5+5;
int dp[maxn];
int main()
{
int N;
while(cin>>N)
{
memset(dp,-0x3f,sizeof(dp));
int len=1;
cin>>dp[1];
for(int i=1;i<N;i++)
{
int t;
cin>>t;
if(t>dp[len])dp[++len]=t;
else
{
int pos=upper_bound(dp+1,dp+1+len,t)-dp;
dp[pos]=t;
}
}
cout<<len<<endl;
}
}