//@begin_of_source_code

/* @JUDGE_ID: 15975FF 111 C++ */

//This is the longest increasing subsequence //algorithm.

#include<iostream.h>

int n;

int A[40];

int B[40];

int C[40];

int Find(int x)

{

int i;

for(i =1; i<= n; i++)

{

if(A

*== x)*

return i;

}

}

int LC()

{

int i,j;

int max;

//bool changed;

int bj, bi;

C[1] = 1;

for( i = 2; i <= n; i++)

{

max = 1;

//changed = false;

for(j = i-1; j >= 1; j--)

{

bj = Find(B[j]);

bi = Find(B

return i;

}

}

int LC()

{

int i,j;

int max;

//bool changed;

int bj, bi;

C[1] = 1;

for( i = 2; i <= n; i++)

{

max = 1;

//changed = false;

for(j = i-1; j >= 1; j--)

{

bj = Find(B[j]);

bi = Find(B

*);*

if(bj < bi && C[j] >= max)

{

//changed = true;

max = C[j]+1;

}

}

Cif(bj < bi && C[j] >= max)

{

//changed = true;

max = C[j]+1;

}

}

C

*= max;*

}

max = 1;

for(i =1; i<= n; i++)

if(C}

max = 1;

for(i =1; i<= n; i++)

if(C

*> max)*

max = Cmax = C

*;*

return max;

}

int main()

{

int i;

int points;

cin>>n;

for(i = 1; i <= n; i++)

cin >> Areturn max;

}

int main()

{

int i;

int points;

cin>>n;

for(i = 1; i <= n; i++)

cin >> A

*;*

//for(i = 1; i <= n; i++)

// cout << A//for(i = 1; i <= n; i++)

// cout << A

*<< ' ';*

//cout << endl;

while(cin >> B[1])

{

for(i = 2; i <=n; i++)

cin >> B//cout << endl;

while(cin >> B[1])

{

for(i = 2; i <=n; i++)

cin >> B

*;*

//for(i = 1; i <= n; i++)

//cout << B//for(i = 1; i <= n; i++)

//cout << B

*<<' ';*

//cout << endl;

points = LC();

cout << points << endl;

}

return 0;

}

//@end_of_source_code//cout << endl;

points = LC();

cout << points << endl;

}

return 0;

}

//@end_of_source_code