#include<bits/stdc++.h>
using namespace std;
const int N=310;
int n,m,a[N][N];
bool test(int x){
	static int cnt[N],p[N];
	bool erase[N];
	for (int i=1;i<=m;i++) erase[i]=0,cnt[i]=0;
	for (int i=1;i<=n;i++) cnt[a[i][p[i]=1]]++;
	int num=0;
	while (1){
		int k=0;
		for (int j=1;j<=m;j++) if (cnt[j]>x) k=j;
		if (!k) return 1;
		num++;
		if (num==m) return 0;
		cnt[k]=0;erase[k]=1;
		for (int j=1;j<=n;j++){
			cnt[a[j][p[j]]]--;
			while (erase[a[j][p[j]]]) p[j]++;
			cnt[a[j][p[j]]]++;
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
		scanf("%d",&a[i][j]);
	int l=1,r=n;
	while (l<r){
		int mid=(l+r)>>1;
		if (test(mid)) r=mid;else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}