#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int M, N,dp[2048][2048],POW[13];
char table[128][12];

int dfs(int question_state, int answer_state){

	if(dp[question_state][answer_state] != -1) return dp[question_state][answer_state];

	int count = 0,tmp;

	for(int i = 0; i < N; i++){

		tmp = 0;
		for(int col = 0; col < M; col++){
			if((question_state  & (1 << col)) && table[i][col] == '1'){
				tmp += POW[col];
			}
		}
		if(tmp == answer_state)count++;
	}

	if(count <= 1){
		return dp[question_state][answer_state] = 0;
	}

	int minimum = M;
	int next_question_state;

	for(int new_quest = 0; new_quest < M; new_quest++){

		if(question_state  & (1 << new_quest))continue;

		next_question_state = question_state + POW[new_quest];

		minimum = min(minimum,max(dfs(next_question_state,answer_state+POW[new_quest]),dfs(next_question_state,answer_state))+1);
	}

	return dp[question_state][answer_state] = minimum;
}


void func(){
	for (int i = 0; i < N; i++) {
		scanf("%s",table[i]);
	}

	for(int i = 0; i < POW[M];i++){
		for(int k = 0; k < POW[M];k++)dp[i][k] = -1;
	}

	printf("%d\n",dfs(0,0));
}

int main() {

	for(int i = 0; i < 13; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d %d",&M,&N);
		if(M == 0 && N == 0)break;

		func();
	}
	return 0;
}