Finding Haplotypes

Everybody inherits two copies of each chromossome (except for the X and Y chromossomes), one for each parent. In some positions of the DNA, (about 0.1% of them) there are variations in the base that is present. These are called Single Nucleotide Polymorfisms (SNPs). In most cases, there are only two possible values in each position, that will be denoted by 0 and 1. When DNA is sequenced, stretches from both copies are pasted together, and is impossible, with present technology, to identify from which chromossome each copy came. Computers are called to help. Your job is to figure out the haplotypes (original chromossomes) that generated a given set of genotypes. A genotype is given by a sequence of 0s, 1s and 2s. A 0 means that the genotype is homozygotic at that position and the SNP has value 0; 1 means that the genotype is homozygotic at that position and the SNP has value 1; and a 2 means the genotype is heterozygotic at that position and that the SNP has value 0 in one haplotype and 1 in the other haplotype. An haplotype is a sequence of 0s and 1s. Given a set of genotypes, the objective is to find a minimum sized set of haplotypes that can be combined in pairs to obtain the given genotypes. For example, given the three genotypes 02120, 20120 and 22110, it is enough to have three haplotpes to explain them: 00100, 10110 and 01110. Haplotype 00100 combines with 10110 to give genotype 20120, and so on. Given a set of genotypes, you should print the minimum number of haplotypes that is necessary to explain it. Input The input file contains several test cases, each of them as describes below. The input file contains two numbers in the first line, that indicate the number of genotypes that follow (N) and the length of each genotype (L). Is is followed by N lines, each with L characters that describe each genotype. N will never be larger than 12 and L will never be larger than 10. Output For each test case, the output should consist of one integer, that represents the minimum number of haplotypes necessary to explain the given genotypes, on a line by itself. Sample Input 35 02120 20120 22110 Sample Output 3