DNA Sequencing

Each printed line can be trimmed to any prefix; pick prefixes of length at least M so the number of distinct resulting strings is maximized.

Medium5TrieStringGreedySortingNo attempts yetTime limit2sMemory limit512 MB

Problem

A customer brought the body of an alien from outer space to a biology lab and asked the lab to extract its DNA sequence. Unlike life on Earth, this DNA does not use the four nucleotides A, C, G and T. It uses all 26 capital English letters, so every DNA sequence is a string of capital letters. The sequencing machine pulled several DNA sequences out of the tissue and printed them on paper, one per line.

Under the contract a sequence is valid only if its length is at least MM, and the customer pays one dollar for each distinct valid sequence. The lab may take a correction pen and erase letters from the end of each printed line. The number of erased letters is chosen separately for each line, and erasing nothing is allowed, so each line becomes some prefix of the sequence that was printed on it.

Choose what to erase so that the number of distinct valid sequences left on the paper is as large as possible, then report that number.

Input

The input contains several test cases. The first line of each test case has two space separated integers kk and MM (1k5001 \le k \le 500, 1M5001 \le M \le 500). Each of the next kk lines has an integer nin_i and a string sis_i separated by a space, which means the sequence sis_i was printed on nin_i lines of the paper (1ni5001 \le n_i \le 500). Each sis_i consists of capital English letters only and its length is between 1 and 500. The same string may appear on more than one of those lines. The last line of the input is 0 0, and that line is not a test case.

Output

For each test case, print one line with the maximum number of distinct valid sequences the lab can produce.