#include <bits/stdc++.h>
using namespace std;
const int N = 310;
int a[N][N],b[N],c[N];
bool pd[N];
int n,m;
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 ans = n;
	for(int i =1;i<=n;i++) b[i] = 1;
	for(int k = 1;k<=m;k++){
		memset(c,0,sizeof(c));
		for(int i =1;i<=n;i++) c[a[i][b[i]]]++;
		int mx = 0,pos = -1;
		for(int i =1;i<=m;i++){
			if(c[i]>mx){
				mx = c[i];
				pos = i;
			}
		}
		ans = min(ans,mx);
		pd[pos] =1;
		for(int i  = 1;i<=n;i++){
			while(b[i]<=m && pd[a[i][b[i]]]) b[i]++;
		}
	}
	printf("%d\n",ans);
	return 0;
}