#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<utility>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int , int> PII;
const int MaxN = 3000;

int a[MaxN + 5][MaxN + 5];
int cnt[MaxN + 5];
queue<int> q[MaxN + 5];
int n, m;

bool check(int x){
	for(int i = 1; i <= m; i++) cnt[i] = 0;
	for(int i = 1; i<= n; i++){
		while(!q[i].empty()) q[i].pop();
		for(int j = 1; j <= m; j++) q[i].push(a[i][j]);
	}
	while(true){
		int p = -1;
		for(int i = 1; i <= n; i++){
			cnt[q[i].front()]++;
			if(cnt[q[i].front()] > x) p = q[i].front();
		}
		if(p == -1) return true;
		for(int i = 1; i <= n; i++){
			if(p == q[i].front()) q[i].pop();
			if(q[i].empty()) return false;
		}
		for(int i = 1; i <= m; i++) cnt[i] = 0;
	}
}

void solve(){
	for(int i = 1; i <= n; i++){
		if(check(i)){
			printf("%d\n", i);
			break;
		}
	}
}

int main(){
	while(~scanf("%d %d", &n, &m)){
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= m; j++)
				scanf("%d", &a[i][j]);
		solve();
	}
	return 0;
}