#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define lowbit(x) (x&(-x))
#define MT(a, b) memset(a,b,sizeof(a))
const int maxn = 2E5 + 15;
const int ONF = -0x3f3f3f3f;
const int INF = 0x3f3f3f3f;
int num[maxn];
int dp[maxn];
int main() {
int n;
while (~scanf ("%d",&n)){
int len=0;
MT(dp,-1);
for (int i=1;i<=n;i++){
scanf ("%d",&num[i]);
}
for (int i=1;i<=n;i++){
if (dp[len]<num[i]) dp[++len]=num[i];
else dp[lower_bound(dp+1,dp+len,num[i])-dp]=num[i];
}
printf("%d\n",len);
}
return 0;
}
相当于dp数组向后推,并且放进来的数字尽量小