#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=300+10;
int cnt[maxn];
int a[maxn][maxn],p[maxn];
bool bz[maxn];
int i,j,k,l,t,n,m,mx,ans;
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n)
		fo(j,1,m)
			scanf("%d",&a[i][j]);
	fo(i,1,n){
		p[i]=1;
		cnt[a[i][1]]++;
	}
	ans=n+1;
	fo(i,1,m){
		mx=0;
		fo(j,1,m)
			if (!bz[j]&&(mx==0||cnt[j]>cnt[mx])) mx=j;
		ans=min(ans,cnt[mx]);
		bz[mx]=1;
		fo(j,1,n)
			if (a[j][p[j]]==mx){
				while (p[j]<m&&bz[a[j][p[j]]]) p[j]++;
				cnt[a[j][p[j]]]++;
			}
	}
	printf("%d\n",ans);
}