Gargari and Permutations

题意翻译

## 题目描述 给你k个长度为n的排列,求这些排列的最长公共子序列的长度 ## 输入格式 第一行包含n(1<=n<=1000)和k(2<=k<=5)。 后面的k行分别表示k个排列。 ## 输出格式 输出最长公共子序列的长度 ## 说明 第一个测试样本的答案是子序列[1,2,3]。

题目描述

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

输入输出格式

输入格式


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.

输出格式


Print the length of the longest common subsequence.

输入输出样例

输入样例 #1

4 3
1 4 2 3
4 1 2 3
1 2 4 3

输出样例 #1

3

说明

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