#include <bits/stdc++.h>

const int N=310;

int n,m,A[N][N],app[N],p[N],chose[N];

void Init() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j) scanf("%d",&A[i][j]);
}

bool check(int ans) {
	for (int i=1;i<=m;++i) app[i]=0,chose[i]=1;
	for (int i=1;i<=n;++i) {
		app[A[i][1]]++; p[i]=1;
	}
	while (1) {
		bool fl=1;
		for (int i=1;i<=n;++i) {
			while (app[A[i][p[i]]]>ans || !chose[A[i][p[i]]]) {
				fl=0;
				chose[A[i][p[i]]]=0;
				p[i]++; app[A[i][p[i]]]++;
				if (p[i]>n) return 0;
			}
		}
		if (fl) break;
	}
	return 1;
}

void Solve() {
	int l=1,r=n;
	while (l<=r) {
		int mid=(l+r)>>1;
		if (check(mid)) r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",l);
}

int main() {
	Init();
	Solve();
	return 0;
}