Under construction

Still being built. Things may change

Keyboard and Virus

Time limit2sMemory limit1024 MB

Summary
Given n symbol sets of size m, find the fewest key presses that always reveal which language the shuffled keyboard is using.
Level

Medium5 of 10

Topics
Hash map, Combinatorics, Implementation
Solved
No attempts yet

Statement

Kolya thinks he is a very cool programmer. He is also a hipster, so he refuses to type on an ordinary keyboard with rubber under the keys. Instead he bought a trendy vintage mechanical keyboard with real springs under each key. The keyboard is so old that every symbol printed on its keys has worn off, but Kolya is not bothered, because he is a very cool programmer.

Kolya types in nn different languages on this keyboard. Conveniently, each language has exactly mm letters, which equals the number of keys on his keyboard. Every symbol of every language is in the encoding Kolya uses, so each symbol is a number from 11 to cc. A symbol may appear in any number of languages, but for any two different languages there is at least one symbol that is in one of them and missing from the other. Some numbers from 11 to cc may not correspond to any symbol Kolya knows.

Kolya's friends are tired of him carrying this keyboard everywhere and annoying people with its loud clicks. They wrote a computer virus that does two nasty things every time the language is switched:

  • Instead of switching to a specific language, it switches to a language chosen at random from the nn languages Kolya uses (the language may stay the same).
  • The keyboard layout for that language is shuffled in an arbitrary way, with only one condition: different keys get different symbols.

When the virus hits, Kolya panics at first, but soon realizes things are not so bad. By pressing each key once, he can find which symbol each key produces, and from that information he can determine the active language. However, he thinks the current language can be determined with fewer key presses. Help Kolya show his friends that he really is a cool programmer by computing the minimum number of key presses he needs in the worst case to determine the current language.

Input

The first line contains two integers nn and mm: the number of languages Kolya uses and the number of keys on his new keyboard (which is also the number of letters in every language).

The next nn lines describe the languages. Each line contains mm symbol numbers in Kolya's encoding. The numbers are given in arbitrary order. All numbers are integers from 11 to cc. The value cc is not given in the input, but it is fixed for each test group.

It is guaranteed that nn, mm, and cc are positive.

Output

Print one integer: the minimum number of keys Kolya must press to determine the current language in the worst case.

Hint

In the first test from the statement, if Kolya is unlucky and presses the keys corresponding to 11 and 33, he cannot tell which language he is typing in.

Examples2

  1. Example 1

    Input
    2 3
    1 2 3
    1 3 4
    
    Expected output
    3
    
  2. Example 2

    Input
    3 2
    1 2
    3 4
    5 6
    
    Expected output
    1