Codeforces Round 264 (Div. 2)
D
Gargari and Permutations
Codeforces
1900
原题
← CE →
翻译中…

Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found $*k*$ permutations. Each of them consists of numbers $1, 2, ..., *n*$ in some order. Now he should find the length of the longest common subsequence of these permutations. Can you help Gargari?

翻译中…

You can read about longest common subsequence there: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*k*$ $(1 ≤ *n* ≤ 1000; 2 ≤ *k* ≤ 5)$. Each of the next $*k*$ lines contains integers $1, 2, ..., *n*$ in some order — description of the current permutation.

翻译中…

Output

翻译中…

Print the length of the longest common subsequence.

翻译中…

Note

翻译中…

The answer for the first test sample is subsequence [1, 2, 3].

翻译中…

样例

Input #1
4 3
1 4 2 3
4 1 2 3
1 2 4 3
Output #1
3
InputCopy OutputCopy
题目信息
题号
463D
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
动态规划
图论
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。