// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

#define FOr(i,x,y)  for(ll i=x;i>=y;--i)

#define For(i,x,y)	for(ll i=x;i<=y;++i)

using namespace std;

namespace SHENZHEBEI{

#ifdef LOCAL

	struct szb{	szb(){	freopen("shenzhebei.in","r",stdin);	}	}shenzhebei;

#endif

#define NEG 1

	const int L=2333333;

	char SZB[L],*S=SZB,*T=SZB;

	inline char gc(){	if (S==T){	T=(S=SZB)+fread(SZB,1,L,stdin);	if (S==T) return '\n';	}	return *S++;	}

#if NEG

	inline ll readint(){	ll x=0,f=1;	char ch=gc();	for (;!isdigit(ch);ch=gc())	if (ch=='-') f=-1;	for (;isdigit(ch);ch=gc())	x=x*10-48+ch;	return x*f;	}

	inline void write(ll x){	if (x<0)	putchar('-'),x=-x;	if (x>=10)	write(x/10);	putchar(x%10+'0');	}

#else

	inline ll readint(){	ll x=0;	char ch=gc();	for (;!isdigit(ch);ch=gc());	for (;isdigit(ch);ch=gc())	x=x*10-48+ch;	return x;	}

	inline void write(ll x){	if (x>=10)	write(x/10);	putchar(x%10+'0');	}

#endif

	inline char readchar(){	char ch=gc();	for(;isspace(ch);ch=gc());	return ch;	}

	inline ll readstr(char *s){	char ch=gc();	int cur=0;	for(;isspace(ch);ch=gc());		for(;!isspace(ch);ch=gc())	s[cur++]=ch;	s[cur]='\0';	return cur;	}

	inline void writeln(ll x){	write(x);	puts("");	}

}using namespace SHENZHEBEI;

const ll N=310;

ll a[N][N],vis[N],sum[N],cho[N],n,m,ans,del[N];

int main(){

	n=readint();	m=readint();

	For(i,1,n)	For(j,1,m)	a[i][j]=readint();

	For(i,1,n)	cho[i]=1,ans=max(ans,++sum[a[i][1]]);

	while(1){

		ll c=0;

		For(i,1,m)	if (sum[i]>sum[c])	c=i;

		ans=min(ans,sum[c]);	del[c]=1;

		For(i,1,n){

			while(del[a[i][cho[i]]]){

				sum[a[i][cho[i]]]--;

				cho[i]++;

				sum[a[i][cho[i]]]++;

			}

			if (cho[i]>m)	return writeln(ans),0;

		}

	}

	writeln(ans);

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

typedef long long ll;



template<typename T>

void input(T &x) {

	x=0; T a=1;

	register char c=getchar();

	for(;c<48||c>57;c=getchar())

		if(c==45) a=-1;

	for(;c>=48&&c<=57;c=getchar())

		x=x*10+c-48;

	x*=a;

	return;

}



#define MAXN 1010

#define MAXM 1010



int n,m;

int a[MAXN][MAXM];

int sum[MAXM];



namespace solve30 { //O(n*m*2^m)

	

	bool chose[15];



	void main() {

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				input(a[i][j]),a[i][j]--;

		int ans=2147483647;

		for(int s=1;s<1<<m;s++) {

			for(int i=0;i<m;i++)

				if(s&(1<<i)) chose[i]=true;

			for(int i=1;i<=n;i++)

				for(int j=1;j<=m;j++)

					if(chose[a[i][j]]) {

						sum[a[i][j]]++;

						break;

					}

			int Max=0;

			for(int i=0;i<m;i++) {

				Max=max(Max,sum[i]),

				sum[i]=0,chose[i]=false;

			}

			ans=min(ans,Max);

		}

		printf("%d\n",ans);

		return;

	}



}



namespace solve70 { // O(n*m*log n)

	

	int cnt[MAXN];

	bool not_chose[MAXM];



	bool Judge(int mid) {

		memset(not_chose,0,sizeof(not_chose));

		for(int i=1;i<=n;i++) cnt[i]=1;

		while(true) {

			memset(sum,0,sizeof(sum));

			bool flag=true;

			for(int i=1;i<=n;i++) {

				for(;cnt[i]<=m&&not_chose[a[i][cnt[i]]];cnt[i]++);

				if(cnt[i]>m) return false;

				if(++sum[a[i][cnt[i]]]>mid)

					not_chose[a[i][cnt[i]]]=true,flag=false;

			}

			if(flag) return true;

		}

		return false;

	}



	void main() {

		for(int i=1;i<=n;i++)

			for(int j=1;j<=m;j++)

				input(a[i][j]);

		int l=1,r=n,ans;

		while(l<=r) {

			int mid=l+r>>1;

			if(Judge(mid)) ans=mid,r=mid-1;

			else l=mid+1;

		}

		printf("%d\n",ans);

		return;

	}



}



int main() {

//	freopen("sports.in","r",stdin),

//	freopen("sports.out","w",stdout),

	input(n),input(m);

	if(n<=10&&m<=10) solve30::main();

	else solve70::main();

//	fclose(stdin),fclose(stdout);

	return 0;

}


// Fastest known solution for this problem: