Twenty Questions

Time limit1sMemory limit128 MB

Summary
Given n objects each described by m binary features, find the minimum worst-case number of adaptive yes/no feature queries needed to identify the hidden object.
Level

Hard8 of 10

Topics
Bit manipulation, Dynamic programming, Brute force
Solved
No attempts yet

Problem

There are nn objects in a room, and each object is described by a set of features. Each feature corresponds to a question that can be answered only with "yes" or "no".

There are mm features in total, and these mm features are enough to tell every object in the room apart. In other words, each object is represented by a boolean (binary) sequence of length mm, and any two distinct objects differ in at least one feature.

You want to figure out which one of the objects in the room a particular hidden object is. To do so, you ask questions to someone who knows all of that object's features. Every question has the form "Does this object have feature jj?", and every answer is "yes" or "no". After hearing each answer, you may choose your next question.

Because each question costs 100 won, you want to ask as few questions (and thus pay as little) as possible. You know the features of every object in the room, but you do not know which of them is the hidden object, so you may plan a strategy (the order of questions and how to branch on the answers) before you start asking.

Assuming you use the best possible strategy, write a program that finds the minimum number of questions that is guaranteed to identify any object in the worst case.

Input

The input consists of several test cases.

The first line of each test case contains the number of features mm and the number of objects nn (0<m≤110 < m \le 11, 0<n≤1280 < n \le 128). Each of the next nn lines describes one object's features as a binary string of length mm, where each position is 1 (yes) or 0 (no). No two objects have exactly the same features.

Output

For each test case, print on its own line the minimum number of questions needed, in the worst case, to distinguish any object when using the best possible strategy.

Examples1

  1. Example 1

    Input
    8 1
    11010101
    11 4
    00111001100
    01001101011
    01010000011
    01100110001
    11 16
    01000101111
    01011000000
    01011111001
    01101101001
    01110010111
    01110100111
    10000001010
    10010001000
    10010110100
    10100010100
    10101010110
    10110100010
    11001010011
    11011001001
    11111000111
    11111011101
    11 12
    10000000000
    01000000000
    00100000000
    00010000000
    00001000000
    00000100000
    00000010000
    00000001000
    00000000100
    00000000010
    00000000001
    00000000000
    9 32
    001000000
    000100000
    000010000
    000001000
    000000100
    000000010
    000000001
    000000000
    011000000
    010100000
    010010000
    010001000
    010000100
    010000010
    010000001
    010000000
    101000000
    100100000
    100010000
    100001000
    100000100
    100000010
    100000001
    100000000
    111000000
    110100000
    110010000
    110001000
    110000100
    110000010
    110000001
    110000000
    0 0
    
    Expected output
    0
    2
    4
    11
    9