Heavy Chain Clusterization
Time limit2sMemory limit256 MB
Split n antibody chains into the fewest groups so each group shares the same first k or last k letters.
Problem
A group of biologists is looking for a cure for a viral disease. They tested many antibodies of different origins against the viral antigens and kept the antibodies that worked best in their experiments.
Every antibody is identified by its heavy chain, a sequence of amino acids. One amino acid is written as one uppercase English letter.
A set of antibodies is a similarity cluster when at least one of the following holds:
- the -prefixes (the first amino acids) of all their heavy chains are equal;
- the -suffixes (the last amino acids) of all their heavy chains are equal.
A set that holds a single antibody is always a similarity cluster.
To make the later research simpler, the biologists want to split the antibodies into similarity clusters, and every antibody has to belong to exactly one cluster. Find how few clusters are enough.
Input
The first line contains two integers and , the number of heavy chains and the length of the amino acid sequence that has to coincide (, ).
Each of the next lines contains the heavy chain of one antibody. Every amino acid is an uppercase English letter, and every heavy chain has at least and at most amino acids.
Output
Print one integer, the minimum number of similarity clusters the antibodies can be split into.