stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

#define N 320

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char ch=getchar();

	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());

	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();

	return f?x:-x;

}

int cnt[N], a[N][N], ans = 1 << 30, at[N], del[N];

int main(int argc, char const *argv[]) {

	int n = read(), m = read();

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

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

			a[i][j] = read();

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

		cnt[a[i][at[i] = 1]] ++;

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

		int * mx = max_element(cnt + 1, cnt + m + 1);

		ans = min(ans, * mx);

		// printf("%d %d %d %d %d\n", cnt[1], cnt[2], cnt[3], cnt[4], cnt[5]);

		// printf("it %d => del %d, %d\n", i, mx - cnt, *mx);

		if (i == m) break;

		del[mx - cnt] = 1;

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

			cnt[a[j][at[j]]] --;

			while (del[a[j][at[j]]])

				++ at[j];

			cnt[a[j][at[j]]] ++;

		}

	}

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

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.149386921685996x):
#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;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



namespace program

{

	const int MAXN = 300, MAXM = 300, INF = 0x3f3f3f3f;

	bool Vis[MAXM + 10];

	int A[MAXN + 10][MAXM + 10];

	int Pos[MAXN + 10];

	vector<int> T[MAXM + 10];



	void work()

	{

		int n, m, ans = INF;

		scanf("%d%d", &n, &m);

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

		{

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

				scanf("%d", &A[i][j]);

			T[A[i][1]].push_back(i);

			Pos[i] = 1;

		}

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

		{

			int mx = 0;

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

				if(!Vis[j] && T[j].size() > T[mx].size())

					mx = j;

			if(T[mx].size() < ans)

				ans = T[mx].size();

			Vis[mx] = 1;

			for(vector<int>::iterator p = T[mx].begin(); p != T[mx].end(); p++)

			{

				while(Vis[A[*p][Pos[*p]]])

					Pos[*p]++;

				T[A[*p][Pos[*p]]].push_back(*p);

			}

		}

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

	}

}



int main()

{

	program::work();

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.225316740705283x):
#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;

}
// Slower C++ solution:
#include <bits/stdc++.h>

 

using namespace std;

 

int n, m, ans, at[305], x[305][305], fre[305], ta;

bool rm[305], o;

 

int main() {

	scanf("%d%d", &n, &m);

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

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

			scanf("%d", x[i] + j);

	for (int i = n; i; i--) {

		memset(at, 0, sizeof(at));

		memset(rm, 0, sizeof(rm));

		o = 1;

		while (1) {

			memset(fre, 0, sizeof(fre));

			for (int j = 0; j < n && o; j++) {

				while (at[j] < m && rm[x[j][at[j]]])

					at[j]++;

				if (at[j] == m)

					o = 0;

				else

					fre[x[j][at[j]]]++;

				//printf("! %d %d %d\n",j,at[j],x[j][at[j]]);

			}

			if (!o)

				break;

			ta = -1;

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

				if (fre[j] > i) {

					rm[j] = 1;

					ta = j;

					break;

				}

		//	printf("%d %d\n",i,ta);

			

		//	for (int j = 0; j < n; j++)

		//	printf("%d%c",at[j],j == n-1 ? '\n':' ' );

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

		//	printf("%d%c",fre[j],j == m ? '\n':' ' );

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

		//	printf("%d%c",rm[j],j == m ? '\n':' ' );

			if (ta == -1)

				break;

		}

		if (o)

			ans = i;

		else

			break;

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.279402367617746x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll int

#define N 305

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,m,ans,a[N][N],now[N],flag[N],tmp[N];

int main(){

	n=ans=read(); m=read();

	rep(i,1,n) rep(j,1,m) a[i][j]=read();

	rep(i,1,n) now[i]=1;

	rep(T,1,m-1){

		rep(i,1,n) while (flag[a[i][now[i]]]) ++now[i];

		ll num=0; memset(tmp,0,sizeof tmp);

		memset(tmp,0,sizeof tmp);

		rep(i,1,n) ++tmp[a[i][now[i]]];

		rep(i,1,m) if (tmp[i]>tmp[num]) num=i;

		ans=min(ans,tmp[num]); flag[num]=1;

	}

	printf("%d",ans);

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<vector>

#include<set>

#include<cmath>

#include<cstdlib>

#include<iostream>

#include<map>



#define Rep(i,x,y) for (int i=x,_Lim=y;i<=_Lim;i++)

#define Dep(i,x,y) for (int i=x,_Lim=y;i>=_Lim;i--)



#define mk(a,b) make_pair(a,b)



using namespace std;



typedef long long ll;

typedef pair<int,int> PII;



int Stv[1<<8];



inline int read(){

	int f=1,res=0,ch=getchar();

	while (ch<'0' || ch>'9'){

		if (ch=='-') f=-1;ch=getchar();

	}

	while (ch>='0' && ch<='9') res=res*10+ch-48,ch=getchar();

	return f*res;

}

const int N=305;



int n,m,Dat[N][N],B[N],Pos[N],Ind[N];

int main(){

	n=read(),m=read();

	Rep(i,1,n) Rep(j,1,m) Dat[i][j]=read();

	Rep(i,1,n) B[Dat[i][1]]++,Pos[i]=1;

	int Ans=n;

	Rep(k,1,m){

		int pos=0,maxval=0;

		Rep(i,1,m) if (B[i]>maxval){

			pos=i;maxval=B[i];

		}

		Ind[pos]=true;

		Rep(i,1,n) if (Dat[i][Pos[i]]==pos){

			Pos[i]++;

			while (Ind[Dat[i][Pos[i]]]) Pos[i]++;

			B[Dat[i][Pos[i]]]++;

		}

		B[pos]=0;

		if (pos==0) break;

		Ans=min(Ans,maxval);

	}

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

}

/*

4 5

5 1 3 4 2

2 5 3 1 4

2 3 1 4 5

2 5 4 3 1

*/

// Faster C++ solution for the same problem (measured speedup: 5.2060522760666315x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll int

#define N 305

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,m,ans,a[N][N],now[N],flag[N],tmp[N];

int main(){

	n=ans=read(); m=read();

	rep(i,1,n) rep(j,1,m) a[i][j]=read();

	rep(i,1,n) now[i]=1;

	rep(T,1,m-1){

		rep(i,1,n) while (flag[a[i][now[i]]]) ++now[i];

		ll num=0; memset(tmp,0,sizeof tmp);

		memset(tmp,0,sizeof tmp);

		rep(i,1,n) ++tmp[a[i][now[i]]];

		rep(i,1,m) if (tmp[i]>tmp[num]) num=i;

		ans=min(ans,tmp[num]); flag[num]=1;

	}

	printf("%d",ans);

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;

const int N = 305;

int a[N][N], id[N], cnt[N];

bool vis[N];

int main()

{

	ios::sync_with_stdio(false);

	int n, m;

	cin >> n >> m;

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

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

			cin >> a[i][j];

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

	{

		id[i] = 1;

		cnt[a[i][1]]++;

	}

	int ans = *max_element(cnt + 1, cnt + m + 1);

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

	{

		vis[max_element(cnt + 1, cnt + m + 1) - cnt] = true;

		fill(cnt + 1, cnt + m + 1, 0);

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

		{

			while (vis[a[j][id[j]]])

				id[j]++;

			cnt[a[j][id[j]]]++;

		}

		ans = min(ans, *max_element(cnt + 1, cnt + m + 1));

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.351318179857493x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll int

#define N 305

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,m,ans,a[N][N],now[N],flag[N],tmp[N];

int main(){

	n=ans=read(); m=read();

	rep(i,1,n) rep(j,1,m) a[i][j]=read();

	rep(i,1,n) now[i]=1;

	rep(T,1,m-1){

		rep(i,1,n) while (flag[a[i][now[i]]]) ++now[i];

		ll num=0; memset(tmp,0,sizeof tmp);

		memset(tmp,0,sizeof tmp);

		rep(i,1,n) ++tmp[a[i][now[i]]];

		rep(i,1,m) if (tmp[i]>tmp[num]) num=i;

		ans=min(ans,tmp[num]); flag[num]=1;

	}

	printf("%d",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

 

using namespace std;

 

int n, m, ans, at[305], x[305][305], fre[305], ta;

bool rm[305], o;

 

int main() {

	scanf("%d%d", &n, &m);

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

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

			scanf("%d", x[i] + j);

	for (int i = n; i; i--) {

		memset(at, 0, sizeof(at));

		memset(rm, 0, sizeof(rm));

		o = 1;

		while (1) {

			memset(fre, 0, sizeof(fre));

			for (int j = 0; j < n && o; j++) {

				while (at[j] < m && rm[x[j][at[j]]])

					at[j]++;

				if (at[j] == m)

					o = 0;

				else

					fre[x[j][at[j]]]++;

				//printf("! %d %d %d\n",j,at[j],x[j][at[j]]);

			}

			if (!o)

				break;

			ta = -1;

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

				if (fre[j] > i) {

					rm[j] = 1;

					ta = j;

					break;

				}

		//	printf("%d %d\n",i,ta);

			

		//	for (int j = 0; j < n; j++)

		//	printf("%d%c",at[j],j == n-1 ? '\n':' ' );

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

		//	printf("%d%c",fre[j],j == m ? '\n':' ' );

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

		//	printf("%d%c",rm[j],j == m ? '\n':' ' );

			if (ta == -1)

				break;

		}

		if (o)

			ans = i;

		else

			break;

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.259984037305303x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#define For(i,j,k) for(int i=j;i<=k;i++)

#define Dow(i,j,k) for(int i=j;i>=k;i--)

#define LL long long

using namespace std;



inline int read() {

	int x = 0,f = 1;

	char ch = getchar();

	while(ch<'0'||ch>'9') { if(ch=='-') f = -1; ch = getchar(); }

	while(ch>='0'&&ch<='9') { x = x *10+ch-48 ; ch = getchar(); }

	return x * f ;

}



const int N = 311;

int n,m,ans;

int a[N][N],cnt[N],vis[N];



int main() {

	n = read(); m = read();

	For(i, 1, n) 

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

	For(i, 1, m) vis[i] = 1; 

	ans = n;

	For(T, 1, m) {

		memset(cnt,0,sizeof cnt);

		For(i, 1, n) 

		  For(j, 1, m) 

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

		    	++cnt[a[i][j]];

		    	break;

			}

		int Mx = 0,id = 0;

		For(i, 1, m) 

			if( cnt[i] > Mx ) Mx = cnt[i],id = i;

		ans = min(Mx,ans);

		vis[id] = 0;

	} 

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

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<vector>

#include<set>

#include<cmath>

#include<cstdlib>

#include<iostream>

#include<map>



#define Rep(i,x,y) for (int i=x,_Lim=y;i<=_Lim;i++)

#define Dep(i,x,y) for (int i=x,_Lim=y;i>=_Lim;i--)



#define mk(a,b) make_pair(a,b)



using namespace std;



typedef long long ll;

typedef pair<int,int> PII;



int Stv[1<<8];



inline int read(){

	int f=1,res=0,ch=getchar();

	while (ch<'0' || ch>'9'){

		if (ch=='-') f=-1;ch=getchar();

	}

	while (ch>='0' && ch<='9') res=res*10+ch-48,ch=getchar();

	return f*res;

}

const int N=305;



int n,m,Dat[N][N],B[N],Pos[N],Ind[N];

int main(){

	n=read(),m=read();

	Rep(i,1,n) Rep(j,1,m) Dat[i][j]=read();

	Rep(i,1,n) B[Dat[i][1]]++,Pos[i]=1;

	int Ans=n;

	Rep(k,1,m){

		int pos=0,maxval=0;

		Rep(i,1,m) if (B[i]>maxval){

			pos=i;maxval=B[i];

		}

		Ind[pos]=true;

		Rep(i,1,n) if (Dat[i][Pos[i]]==pos){

			Pos[i]++;

			while (Ind[Dat[i][Pos[i]]]) Pos[i]++;

			B[Dat[i][Pos[i]]]++;

		}

		B[pos]=0;

		if (pos==0) break;

		Ans=min(Ans,maxval);

	}

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

}

/*

4 5

5 1 3 4 2

2 5 3 1 4

2 3 1 4 5

2 5 4 3 1

*/

// Faster C++ solution for the same problem (measured speedup: 5.186903736955352x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#define For(i,j,k) for(int i=j;i<=k;i++)

#define Dow(i,j,k) for(int i=j;i>=k;i--)

#define LL long long

using namespace std;



inline int read() {

	int x = 0,f = 1;

	char ch = getchar();

	while(ch<'0'||ch>'9') { if(ch=='-') f = -1; ch = getchar(); }

	while(ch>='0'&&ch<='9') { x = x *10+ch-48 ; ch = getchar(); }

	return x * f ;

}



const int N = 311;

int n,m,ans;

int a[N][N],cnt[N],vis[N];



int main() {

	n = read(); m = read();

	For(i, 1, n) 

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

	For(i, 1, m) vis[i] = 1; 

	ans = n;

	For(T, 1, m) {

		memset(cnt,0,sizeof cnt);

		For(i, 1, n) 

		  For(j, 1, m) 

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

		    	++cnt[a[i][j]];

		    	break;

			}

		int Mx = 0,id = 0;

		For(i, 1, m) 

			if( cnt[i] > Mx ) Mx = cnt[i],id = i;

		ans = min(Mx,ans);

		vis[id] = 0;

	} 

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

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;

const int N = 305;

int a[N][N], id[N], cnt[N];

bool vis[N];

int main()

{

	ios::sync_with_stdio(false);

	int n, m;

	cin >> n >> m;

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

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

			cin >> a[i][j];

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

	{

		id[i] = 1;

		cnt[a[i][1]]++;

	}

	int ans = *max_element(cnt + 1, cnt + m + 1);

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

	{

		vis[max_element(cnt + 1, cnt + m + 1) - cnt] = true;

		fill(cnt + 1, cnt + m + 1, 0);

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

		{

			while (vis[a[j][id[j]]])

				id[j]++;

			cnt[a[j][id[j]]]++;

		}

		ans = min(ans, *max_element(cnt + 1, cnt + m + 1));

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.331635333810215x):
#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#define For(i,j,k) for(int i=j;i<=k;i++)

#define Dow(i,j,k) for(int i=j;i>=k;i--)

#define LL long long

using namespace std;



inline int read() {

	int x = 0,f = 1;

	char ch = getchar();

	while(ch<'0'||ch>'9') { if(ch=='-') f = -1; ch = getchar(); }

	while(ch>='0'&&ch<='9') { x = x *10+ch-48 ; ch = getchar(); }

	return x * f ;

}



const int N = 311;

int n,m,ans;

int a[N][N],cnt[N],vis[N];



int main() {

	n = read(); m = read();

	For(i, 1, n) 

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

	For(i, 1, m) vis[i] = 1; 

	ans = n;

	For(T, 1, m) {

		memset(cnt,0,sizeof cnt);

		For(i, 1, n) 

		  For(j, 1, m) 

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

		    	++cnt[a[i][j]];

		    	break;

			}

		int Mx = 0,id = 0;

		For(i, 1, m) 

			if( cnt[i] > Mx ) Mx = cnt[i],id = i;

		ans = min(Mx,ans);

		vis[id] = 0;

	} 

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

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

 

using namespace std;

 

int n, m, ans, at[305], x[305][305], fre[305], ta;

bool rm[305], o;

 

int main() {

	scanf("%d%d", &n, &m);

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

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

			scanf("%d", x[i] + j);

	for (int i = n; i; i--) {

		memset(at, 0, sizeof(at));

		memset(rm, 0, sizeof(rm));

		o = 1;

		while (1) {

			memset(fre, 0, sizeof(fre));

			for (int j = 0; j < n && o; j++) {

				while (at[j] < m && rm[x[j][at[j]]])

					at[j]++;

				if (at[j] == m)

					o = 0;

				else

					fre[x[j][at[j]]]++;

				//printf("! %d %d %d\n",j,at[j],x[j][at[j]]);

			}

			if (!o)

				break;

			ta = -1;

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

				if (fre[j] > i) {

					rm[j] = 1;

					ta = j;

					break;

				}

		//	printf("%d %d\n",i,ta);

			

		//	for (int j = 0; j < n; j++)

		//	printf("%d%c",at[j],j == n-1 ? '\n':' ' );

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

		//	printf("%d%c",fre[j],j == m ? '\n':' ' );

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

		//	printf("%d%c",rm[j],j == m ? '\n':' ' );

			if (ta == -1)

				break;

		}

		if (o)

			ans = i;

		else

			break;

	}

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

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.244707221180716x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

const int inf=1e8,maxn=305;

inline int read(){int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}

int n,m,ans,cnt[maxn],a[maxn][maxn];

bool cho[maxn];

inline void init(){

	n=read(); m=read();

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

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

			a[i][j]=read();

		}

	}

	ans=inf;

	memset(cho,1,sizeof(cho));

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

		memset(cnt,0,sizeof(cnt));

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

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

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

					cnt[a[i][j]]++;

					break;

				}

			}

		}

		int mx=0;

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

			if ((!mx)||(mx&&cnt[mx]<cnt[i])){

				mx=i;

			}

		}

		cho[mx]=0;

		ans=min(cnt[mx],ans);

	}

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

}

int main(){

	init();

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<vector>

#include<set>

#include<cmath>

#include<cstdlib>

#include<iostream>

#include<map>



#define Rep(i,x,y) for (int i=x,_Lim=y;i<=_Lim;i++)

#define Dep(i,x,y) for (int i=x,_Lim=y;i>=_Lim;i--)



#define mk(a,b) make_pair(a,b)



using namespace std;



typedef long long ll;

typedef pair<int,int> PII;



int Stv[1<<8];



inline int read(){

	int f=1,res=0,ch=getchar();

	while (ch<'0' || ch>'9'){

		if (ch=='-') f=-1;ch=getchar();

	}

	while (ch>='0' && ch<='9') res=res*10+ch-48,ch=getchar();

	return f*res;

}

const int N=305;



int n,m,Dat[N][N],B[N],Pos[N],Ind[N];

int main(){

	n=read(),m=read();

	Rep(i,1,n) Rep(j,1,m) Dat[i][j]=read();

	Rep(i,1,n) B[Dat[i][1]]++,Pos[i]=1;

	int Ans=n;

	Rep(k,1,m){

		int pos=0,maxval=0;

		Rep(i,1,m) if (B[i]>maxval){

			pos=i;maxval=B[i];

		}

		Ind[pos]=true;

		Rep(i,1,n) if (Dat[i][Pos[i]]==pos){

			Pos[i]++;

			while (Ind[Dat[i][Pos[i]]]) Pos[i]++;

			B[Dat[i][Pos[i]]]++;

		}

		B[pos]=0;

		if (pos==0) break;

		Ans=min(Ans,maxval);

	}

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

}

/*

4 5

5 1 3 4 2

2 5 3 1 4

2 3 1 4 5

2 5 4 3 1

*/

// Faster C++ solution for the same problem (measured speedup: 5.171839171343858x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

const int inf=1e8,maxn=305;

inline int read(){int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}

int n,m,ans,cnt[maxn],a[maxn][maxn];

bool cho[maxn];

inline void init(){

	n=read(); m=read();

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

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

			a[i][j]=read();

		}

	}

	ans=inf;

	memset(cho,1,sizeof(cho));

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

		memset(cnt,0,sizeof(cnt));

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

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

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

					cnt[a[i][j]]++;

					break;

				}

			}

		}

		int mx=0;

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

			if ((!mx)||(mx&&cnt[mx]<cnt[i])){

				mx=i;

			}

		}

		cho[mx]=0;

		ans=min(cnt[mx],ans);

	}

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

}

int main(){

	init();

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;

const int N = 305;

int a[N][N], id[N], cnt[N];

bool vis[N];

int main()

{

	ios::sync_with_stdio(false);

	int n, m;

	cin >> n >> m;

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

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

			cin >> a[i][j];

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

	{

		id[i] = 1;

		cnt[a[i][1]]++;

	}

	int ans = *max_element(cnt + 1, cnt + m + 1);

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

	{

		vis[max_element(cnt + 1, cnt + m + 1) - cnt] = true;

		fill(cnt + 1, cnt + m + 1, 0);

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

		{

			while (vis[a[j][id[j]]])

				id[j]++;

			cnt[a[j][id[j]]]++;

		}

		ans = min(ans, *max_element(cnt + 1, cnt + m + 1));

	}

	cout << ans << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.316150417494824x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

const int inf=1e8,maxn=305;

inline int read(){int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}

int n,m,ans,cnt[maxn],a[maxn][maxn];

bool cho[maxn];

inline void init(){

	n=read(); m=read();

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

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

			a[i][j]=read();

		}

	}

	ans=inf;

	memset(cho,1,sizeof(cho));

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

		memset(cnt,0,sizeof(cnt));

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

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

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

					cnt[a[i][j]]++;

					break;

				}

			}

		}

		int mx=0;

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

			if ((!mx)||(mx&&cnt[mx]<cnt[i])){

				mx=i;

			}

		}

		cho[mx]=0;

		ans=min(cnt[mx],ans);

	}

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

}

int main(){

	init();

	return 0;

}