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

using namespace std;

int n,m,a[305][305];

int cnt[305],vis[305],ans=1e9;

int findmax(){

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

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

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

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

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

				break;

			}

	int mx=0;

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

		if (cnt[i]>cnt[mx]) mx=i;

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

	return mx;

}

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]);

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

		vis[findmax()]=1;

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

}

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

#include<algorithm>

#include<string.h>

#include<math.h>

#include<stdlib.h>

#include<bitset>

#include<map>

#include<queue>

#include<vector>

#include<set>

#include<iostream>

#include<string>

#define ll long long

#define N 305

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

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

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

using namespace std;

int read(){int x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}

void write(int x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}

void writeln(int x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}

int n,m,a[N][N],b[N],sum,l[N];

bool flag[N];

int main(){

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

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

	For(i,1,n) b[a[i][1]]++;

	For(i,1,n) l[i]=1;

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

	For(i,1,m) sum=max(sum,b[i]);

	For(i,1,m-1){

		int mxj=0;For(j,1,m) if(b[j]>b[mxj]) mxj=j;

		flag[mxj]=0;

		For(j,1,n) if(a[j][l[j]]==mxj){

			b[a[j][l[j]]]--;

			while(!flag[a[j][l[j]]]) l[j]++;

			b[a[j][l[j]]]++;

		}

		int mx=0;

		For(j,1,m) mx=max(mx,b[j]);

		sum=min(sum,mx);

	}

	writeln(sum);

	return 0;

}

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

#define Ll long long

using namespace std;

const int N=3e2+5;

int a[N][N],d[N];

bool ok[N];

int ans=1e9,n,m,x;

int find(){

	memset(d,0,sizeof d);

	int ma=0;

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

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

			if(!ok[a[i][j]]){

				d[a[i][j]]++;

				break;

			}

	for(int i=1;i<=m;i++)ma=max(ma,d[i]);

	for(int i=1;i<=m;i++)if(d[i]==ma)ok[i]=1;

	return ma;

}

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]);

	while(1){

		int sum=0;

		for(int i=1;i<=m;i++)if(!ok[i])sum++;

		if(sum==0)break;

		ans=min(find(),ans);

	}

	printf("%d",ans);

}

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

#include <cstring>

#include <algorithm>

#include <iostream>

#include <set>

using namespace std;



typedef long long ll;

typedef pair<int, int> pii;



const int KN = 305;



int n, m, a[KN][KN], pos[KN][KN], cnt[KN];



set<pii> S[KN];



bool check(int mid) {

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

		S[i].clear();

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

			S[i].insert(make_pair(j, a[i][j]));

	}

	int idx;

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

		bool can = true;

		memset(cnt, 0x00, sizeof cnt);

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

			++cnt[S[i].begin()->second];

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

			if (cnt[i] > mid)

				can = false, idx = i;

		if (can)

			return true;

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

			S[i].erase(make_pair(pos[i][idx], idx));

	}

	return false;

}



int main() {

	ios::sync_with_stdio(false);

	cin >> n >> m;

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

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

			cin >> a[i][j];

			pos[i][a[i][j]] = j;

		}

	int low = 0, high = n, ans = high;

	while (low <= high) {

		int mid = (low + high) >> 1;

		if (check(mid))

			ans = mid, high = mid - 1;

		else low = mid + 1;

	}

	cout << ans << endl;

	return 0;

}

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

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

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

		while(1) {

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

			bool flag=true;

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

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

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

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

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

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		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 0;

	}



}



int main() { return solve70::main(); }
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

int n,m,a[305][305];

int cnt[305],vis[305],ans=1e9;

int findmax(){

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

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

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

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

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

				break;

			}

	int mx=0;

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

		if (cnt[i]>cnt[mx]) mx=i;

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

	return mx;

}

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]);

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

		vis[findmax()]=1;

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

}

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

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

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

		while(1) {

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

			bool flag=true;

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

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

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

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

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

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		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 0;

	}



}



int main() { return solve70::main(); }
// Slower C++ solution:
#include<stdio.h>

#include<algorithm>

#include<string.h>

#include<math.h>

#include<stdlib.h>

#include<bitset>

#include<map>

#include<queue>

#include<vector>

#include<set>

#include<iostream>

#include<string>

#define ll long long

#define N 305

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

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

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

using namespace std;

int read(){int x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}

void write(int x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}

void writeln(int x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}

int n,m,a[N][N],b[N],sum,l[N];

bool flag[N];

int main(){

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

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

	For(i,1,n) b[a[i][1]]++;

	For(i,1,n) l[i]=1;

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

	For(i,1,m) sum=max(sum,b[i]);

	For(i,1,m-1){

		int mxj=0;For(j,1,m) if(b[j]>b[mxj]) mxj=j;

		flag[mxj]=0;

		For(j,1,n) if(a[j][l[j]]==mxj){

			b[a[j][l[j]]]--;

			while(!flag[a[j][l[j]]]) l[j]++;

			b[a[j][l[j]]]++;

		}

		int mx=0;

		For(j,1,m) mx=max(mx,b[j]);

		sum=min(sum,mx);

	}

	writeln(sum);

	return 0;

}

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

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

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

		while(1) {

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

			bool flag=true;

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

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

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

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

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

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		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 0;

	}



}



int main() { return solve70::main(); }
// Slower C++ solution:
#include<bits/stdc++.h>

#define Ll long long

using namespace std;

const int N=3e2+5;

int a[N][N],d[N];

bool ok[N];

int ans=1e9,n,m,x;

int find(){

	memset(d,0,sizeof d);

	int ma=0;

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

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

			if(!ok[a[i][j]]){

				d[a[i][j]]++;

				break;

			}

	for(int i=1;i<=m;i++)ma=max(ma,d[i]);

	for(int i=1;i<=m;i++)if(d[i]==ma)ok[i]=1;

	return ma;

}

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]);

	while(1){

		int sum=0;

		for(int i=1;i<=m;i++)if(!ok[i])sum++;

		if(sum==0)break;

		ans=min(find(),ans);

	}

	printf("%d",ans);

}

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

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

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

		while(1) {

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

			bool flag=true;

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

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

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

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

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

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		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 0;

	}



}



int main() { return solve70::main(); }
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

inline void read(int &x)

{

	char c=getchar();

	x=0;

	while (c>'9'||c<'0')

		c=getchar();

	while (c>='0'&&c<='9')

	{

		x=x*10+c-'0';

		c=getchar();

	}

}

const int N=305;

int a[N][N],p[N],f[N],n,m,ans=23333333,pos,b[N];

int main()

{

	read(n);

	read(m);

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

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

			read(a[i][j]);

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

		p[i]=1;

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

	{

		memset(f,0,sizeof(f));

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

		{

			while (b[a[j][p[j]]]&&p[j]<=m)

				++p[j];

			++f[a[j][p[j]]];

		}

		pos=1;

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

			if (f[j]>f[pos])

				pos=j;

		b[pos]=1;

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

			cout<<f[i]<<' ';

		cout<<'\n';*/

		ans=min(ans,f[pos]);

	}

	cout<<ans;

}

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

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

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

		while(1) {

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

			bool flag=true;

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

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

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

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

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

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		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 0;

	}



}



int main() { return solve70::main(); }
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int n, m, temp, ans, a[305][305];



bool C(int ppl)

{

    bool choose[305]; //choose i-th sport

    memset(choose, true, sizeof(choose));



    while(true) {

        int cnt[305]; //count of i-th sport

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

        bool used = true;



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

            int now = 1; //place of i-th sport that can be choose

            for(now=1; now<=m; now++) {

                if(choose[a[i][now]]) break;

            }

            if(now > m) return false;

            cnt[a[i][now]]++;

            if(cnt[a[i][now]] > ppl) {

                choose[a[i][now]] = false;

                used = false;

            }

        }

        if(used) return true;

    }

}



int main()

{

    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m;

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

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

            cin >> a[i][j];



    int lb=1, ub=n, mid=0;

    while(lb<=ub) {

        mid = (lb+ub)/2;

        if(C(mid)) {

            ans = mid;

            ub = mid-1;

        }

        else lb = mid+1;

    }

    cout << ans << endl;



    return 0;

}


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

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

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

		while(1) {

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

			bool flag=true;

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

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

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

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

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

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		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 0;

	}



}



int main() { return solve70::main(); }
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define FOR(i,a,b) for(int i = (a); i < (b); i++)

#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)

#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a, value) memset(a, value, sizeof(a))



#define SZ(a) (int) a.size()

#define ALL(a) a.begin(),a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const LL INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 333;



int A[MAX][MAX];

int C[MAX];

int P[MAX];

bool U[MAX];



int main()

{

	//freopen("in.txt", "r", stdin);

	//ios::sync_with_stdio(false); cin.tie(0);



	int n, m;

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

	FOR (i, 0, n)

	{

		FOR (j, 0, m)

		{

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

			A[i][j]--;

		}

	}



	int L = 0, R = n + 1;

	while(R - L > 1)

	{

		int M = (L + R) / 2;



		//M = 1;

		FILL(C, 0);

		FILL(U, 0);

		FOR (i, 0, n)

		{

			P[i] = 0;

			C[A[i][0]]++;

		}



		bool ok = false;



		while(true)

		{

			int ind = -1;

			FOR (i, 0, m)

			{

				if (C[i] > M)

				{

					ind = i;

					break;

				}

			}





			if (ind == -1)

			{

				ok = true;

				break;

			}



			U[ind] = true;



			bool okk = true;



			FOR (i, 0, n)

			{

				while(P[i] < m && U[A[i][P[i]]])

				{

					C[A[i][P[i]]]--;

					P[i]++;

					if (P[i] >= m)

					{

						okk = false;

						break;

					}

					C[A[i][P[i]]]++;

				}

				if (!okk || P[i] >= m)

				{

					okk = false;

					break;

				}

			}



			if (!okk)

			{

				ok = false;

				break;

			}

		}



		if (ok) R = M;

		else L = M;

	}



	cout<<R<<endl;

}


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

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

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

		while(1) {

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

			bool flag=true;

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

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

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

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

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

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		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 0;

	}



}



int main() { return solve70::main(); }
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



const int N=505;



int n,m;

int a[N][N],num[N];

bool vis[N];



void work()

{

    int ans=n;

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

		memset(num,0,sizeof(num)); 

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

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

				if(vis[a[i][j]]){num[a[i][j]]++;break;}

		int mx=0,id=0;

        for(int i=1;i<=m;i++) if(num[i]>=mx) mx=num[i],id=i;

        ans=min(ans,mx);

        vis[id]=0;

	}

	cout<<ans<<endl;

}



void init()

{

	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<=m;i++) vis[i]=1;

}



int main()

{

	init();

	work();

	return 0;

}


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

}



int n,m;



namespace solve70 {

	

	const int N=310;

	const int M=310;

	int a[N][M],cnt[N],sum[N];

	bool go[M];



	bool Judge(int mid) {

		memset(go,0,sizeof(go));

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

		while(1) {

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

			bool flag=true;

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

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

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

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

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

			}

			if(flag) return true;

		}

		return false;

	}



	int main() {

		input(n),input(m);

		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 0;

	}



}



int main() { return solve70::main(); }