/**
** Java Program to implement Longest Increasing Subsequence Algorithm
**/
import java.util.Scanner;
/** Class LongestIncreasingSubsequence **/
class LongestIncreasingSubsequence
{ int fuc=0;
/** function lis **/
public int[] lis(int[] X)
{ fuc++;
int n = X.length - 1;
int[] M = new int[n + 1];
int[] P = new int[n + 1];
int L = 0;
for (int i = 1; i < n + 1; i++)
{
int j = 0;
/** Linear search applied here. Binary Search can be applied too.
binary search for the largest positive j <= L such that
X[M[j]] < X[i] (or set j = 0 if no such value exists) **/
for (int pos = L ; pos >= 1; pos--)
{
if (X[M[pos]] < X[i])
{
j = pos;
break;
}
}
P[i] = M[j];
if (j == L || X[i] < X[M[j + 1]])
{
M[j + 1] = i;
}
}
/** backtrack **/
int[] result = new int[L];
int pos = M[L];
for (int i = L - 1; i >= 0; i--)
{
result[i] = pos;
pos = P[pos];
}
return result;
}
/** Main Function **/
public static void main
(String[] args
) {
Scanner scan
= new Scanner
(System.
in);
int n = scan.nextInt();
int[] arr = new int[n+1];
for (int i = 1; i <= n; i++)
arr[i] = scan.nextInt();
LongestIncreasingSubsequence obj = new LongestIncreasingSubsequence();
int [] result=new int[n+1];
int [] far=new int[n+1];
/*for (int i = 1; i <=n; i++){
result[i]=arr[i];
}*/
// System.arraycopy( arr, 0, result, 0, arr.length );
int t=0;
while(true)
{if(t==n)
break;
int chount=0;
for (int i = 0; i <=result.length-1; i++)
{ //System.out.print(result[i]+" ");
if(arr[result[i]]!=-1)
arr[result[i]]=-1;
}
t++;
//System.out.println("");
int k=1,fk=1;
for (int i = 1; i <=arr.length-1; i++)
{
if(arr[i]!=-1)
{
k++;
}
}
far=new int[k];
for (int i = 1; i <=arr.length-1; i++)
{
if(arr[i]!=-1)
{
far[fk]=arr[i];
fk++;
}
}
for (int i = 1; i <=arr.length-1; i++)
if(arr[i]==-1)
{
chount++;
}
//System.out.println("");
if(chount==arr.length-1)
break;
// System.out.println("func");
// for (int i = 1; i <=fk-1; i++)
// System.out.print(far[i]+" frr"+far.length );
// obj = new LongestIncreasingSubsequence();
result=obj.lis(far);
}
}
}