#include <bits/stdc++.h>
using namespace std;
vector <int> v[305];
int n, k;
const int inf = 1e8;
int cnt[305];

int solve() {	
	if(v[1].empty()) {
		return inf;
	}	
	memset(cnt, 0, sizeof cnt);
	for(int i = 1; i <= n; i++) {
		cnt[v[i].front()] += 1;
	}
	
	int ans = 0;
	int bad = 0;
	for(int i = 1; i <= k; i++) {
		if(ans < cnt[i]) {
			ans = cnt[i];
			bad = i;
		}
	}
	for(int i = 1; i <= n; i++) {
		v[i].erase(find(v[i].begin(), v[i].end(), bad));
	}
	return min(ans, solve());
}
int main (int argc, char const* argv[])
{
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= k; j++) {
			int x;
			scanf("%d", &x);
			v[i].push_back(x);
		}
	}	
	printf("%d\n", solve());
	return 0;
}