import java.util.*;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
int trees = Integer.parseInt(in.nextLine().trim());
int[] peaches = new int[trees];
for (int i = 0; i < trees; i++) {
peaches[i] = Integer.parseInt(in.nextLine());
}
int[] revP = new int[trees];
for(int i = 0; i < trees; i++){
revP[i] = peaches[i];
}
Arrays.sort(revP);
int len1 = peaches.length;
int len2 = revP.length;
int[][] dp = new int[len1+1][len2+1];
for(int i = 0; i < len1; i++){
for(int j = 0; j < len2; j++){
if(peaches[i] == revP[j]){
dp[i+1][j+1] = dp[i][j] + 1;
}else{
dp[i+1][j+1] = Math.max(dp[i][j+1], dp[i+1][j]) > dp[i][j] ? Math.max(dp[i][j+1],dp[i+1][j]) : dp[i][j];
}
}
}
System.out.println(dp[len1][len2]);
}
in.close();
}
}
AC