Problem: Consider a closed world and a set of features that are defined for all the objects in the world. Each feature can be answered with "yes" or "no". Using those features, we can identify any object from the rest of the objects in the world. In other words, each object can be represented as a fixed-length sequence of booleans. Any object is different from other objects by at least one feature.

You would like to identify an object from others. For this purpose, you can ask a series of questions to someone who knows what the object is. Every question you can ask is about one of the features. He/she immediately answers each question with "yes" or "no" correctly. You can choose the next question after you get the answer to the previous question.

You kindly pay the answerer 100 yen as a tip for each question. Because you don' t have surplus money, it is necessary to minimize the number of questions in the worst case. You don’t know what is the correct answer, but fortunately know all the objects in the world. Therefore, you can plan an optimal strategy before you start questioning.

The problem you have to solve is: given a set of boolean-encoded objects, minimize the maximum number of questions by which every object in the set is identifiable.



Input

The input is a sequence of multiple datasets. Each dataset begins with a line which consists of two integers, m and n: the number of features, and the number of objects, respectively. You can assume 0 < m ≤ 11 and 0 < n ≤ 128. It is followed by n lines, each of which corresponds to an object. Each line includes a binary string of length m which represent the value ("yes" or "no") of features. There are no two identical objects.

The end of the input is indicated by a line containing two zeros. There are at most 100 datasets.

Output

For each dataset, minimize the maximum number of questions by which every object is identifiable and output the result.

Example

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


Output

0
2
4
11
9

Solution (in CPP):

Solution:
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

//li chao tree by ei1333. It's public available.
// https://ei1333.github.io/luzhiled/snippets/structure/li-chao-tree.html
/*
template< typename T >
struct LiChaoTree {
    struct Line {
        T a, b;

        Line(T a, T b) : a(a), b(b) {}

        inline T get(T x) const { return a * x + b; }

        inline bool over(const Line& b, const T& x) const {
            return get(x) < b.get(x);
        }
    };

    vector< T > xs;
    vector< Line > seg;
    int sz;

    LiChaoTree(const vector< T >& x, T INF) : xs(x) {
        sz = 1;
        while (sz < xs.size()) sz <<= 1;
        while (xs.size() < sz) xs.push_back(xs.back() + 1);
        seg.assign(2 * sz - 1, Line(0, INF));
    }

    void update(Line& x, int k, int l, int r) {
        int mid = (l + r) >> 1;
        auto latte = x.over(seg[k], xs[l]), malta = x.over(seg[k], xs[mid]);
        if (malta) swap(seg[k], x);
        if (l + 1 >= r) return;
        else if (latte != malta) update(x, 2 * k + 1, l, mid);
        else update(x, 2 * k + 2, mid, r);
    }

    void update(T a, T b) { // ax+b
        Line l(a, b);
        update(l, 0, 0, sz);
    }

    T query(int k) { // xs[k]
        const T x = xs[k];
        k += sz - 1;
        T ret = seg[k].get(x);
        while (k > 0) {
            k = (k - 1) >> 1;
            ret = min(ret, seg[k].get(x));
        }
        return ret;
    }
};

#define int long long
void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> landmarks;
    vector<vector<int>> costs;
    REP(i, n) {
        vector<int> tmp;
        REP(q, m) {
            int b;
            cin >> b;
            b = xor128() % 10000000;
            tmp.push_back(b);
        }
        landmarks.push_back(tmp);
    }
    REP(i, n) {

        vector<int> tmp;
        {
            REP(q, m) {
                int b;
                cin >> b;
                b = xor128() % 100000000;
                tmp.push_back(b);
            }
        }
        costs.push_back(tmp);
    }
    vector<LiChaoTree<int>> yoko; // size should be m
    REP(i, n) {
        vector<int> hoge(m);
        REP(q, m) {
            hoge[q] = q;
        }
        LiChaoTree<int> now(hoge, 1e18);//size should be n
        yoko.push_back(now);
    }
    vector<vector<int>> dp = landmarks;
    for (int q = 0; q < m; ++q) {
        vector<int> hoge(n);
        REP(i, n) {
            hoge[i] = i;
        }
        LiChaoTree<int> now(hoge, 1e18);//size should be n

        for (int i = 0; i < n; ++i) {
            int now_min = costs[0][0] * (i + q);
            if (q < 0) {
                int geko = yoko[i].query(q);
                now_min = min(now_min, geko);
            }
            if (i != 0) {
                int geko = now.query(i);
                now_min = min(now_min, geko);
            }
            dp[i][q] = now_min;
            yoko[i].update(costs[i][q], landmarks[i][q] + dp[i][q] - q * costs[i][q]);
            now.update(costs[i][q], landmarks[i][q] + dp[i][q] - i * costs[i][q]);
        }
    }

    cout << dp[n - 1][m - 1] << endl;
}
*/

#define int ll
int dp[177147];
int bit[100];
int n, m;
vector<int> inputs;
int dfs(int now) {
    if (dp[now] != -1) return dp[now];
    int diff = 0;
    int comp = 0;
    int hoge = now;
    for (int q = 0; q < n; ++q) {
        if (hoge % 3 != 2) {
            comp += (1 << q);
            diff += (1 << q) * (hoge % 3);
        }
        hoge /= 3;
    }
    int cnt = 0;
    REP(i, inputs.size()) {
        if ((inputs[i] & comp) == diff) {
            cnt++;
        }
    }
    if (cnt == 1) return dp[now] = 0;
    else if(cnt == 0) return dp[now] = -1e9;
    int ans = 100;
    hoge = now;
    for (int q = 0; q < n; ++q) {
        if (hoge % 3 == 2) {
            int tmp = now - bit[q] * 2;
            int tea = max(dfs(tmp), dfs(tmp + bit[q]));
            if (tea == -1e9) continue;
            ans = min(ans,tea + 1);
        }
        hoge /= 3;
    }
    return dp[now] = ans;
}

void solve(){
    bit[0] = 1;
    for (int q = 1; q < 13; ++q) {
        bit[q] = bit[q - 1] * 3;
    }
    while (true) {
        cin >> n >> m;
        if (n == 0) return;
        REP(i, 177147) {
            dp[i] = -1;
        }
        inputs.clear();
        REP(i, m) {
            string s;
            cin >> s;
            int a = 0;
            REP(q, s.length()) {
                if (s[q] == '1') {
                    a += (1 << q);
                }
            }
            inputs.push_back(a);
        }
        cout << dfs(bit[n] - 1) << endl;
    }
}
#undef int
int main() {
    init();
    solve();
}