跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1919. Gargari and Permutations

    ID: 1925 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索动态规划图论模拟编程与模拟提高难度共享题库Codeforces英文题面题目来源题面语言

Gargari and Permutations

题目描述

D. Gargari and Permutations
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
Input
4 3
1 4 2 3
4 1 2 3
1 2 4 3
Output
3
Note

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


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 1497 题。保留原作者与原赛事署名。