#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
*/