Mock CCC '22 2 S2 - Kaguya Wants to Grow the Student Council

View as PDF

Points: 10 (partial)
Time limit: 0.25s
Memory limit: 1G

Problem type

It's time to elect a new student council!

There are candidates who want to join the student council. Each of the students submits a ballot containing a permutation of the given candidates. Kaguya wants the council to be as large as possible so that she can spend less time doing administrative work and more time getting Miyuki to confess his love for her. However, because the council positions are ranked, Kaguya cannot simply put every candidate on the student council. In particular, if Kaguya puts candidate and candidate on the council, with candidate ranked higher on the council than candidate , then every student who submitted a ballot must have ranked candidate higher than candidate .

Compute the maximum possible size of the council Kaguya can generate.

Constraints

In tests worth 1 mark, .

In tests worth an additional 4 marks, .

Input Specification

The first line contains two integers, and .

Each of the next lines contains a string of length , consisting of a permutation of the first uppercase letters.

Output Specification

Output the maximum possible size of the council.

Sample Input 1

2 3
BAC
ABC

Sample Output 1

2

Sample Input 2

3 8
HGBDFCAE
HCFGBDAE

Sample Output 2

3

Sample Input 3

6 8
AHFBGDCE
FABGCEHD
AHDGFBCE
DABHGCFE
ABCHFEDG
DGABHFCE

Sample Output 3

4