Longest Common Subsequence

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

You are given nn strings, each a permutation of the first kk upper-case letters of the alphabet.

String ss is a subsequence of string tt if and only if it is possible to delete some (possibly zero) characters from the string tt to get the string ss.

Compute the length of the longest common subsequence of all nn strings.

입력

The first line of input contains two integers nn (1n1051 \le n \le 10^5) and kk (1k261 \le k \le 26), where nn is the number of strings, and the strings are all permutations of the first kk upper-case letters of the alphabet.

Each of the next nn lines contains a single string tt. It is guaranteed that every tt contains each of the first kk upper-case letters of the alphabet exactly once.

출력

Output a single integer, the length of the longest subsequence that appears in all nn strings.