#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 302

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
bool killed[N];
char ch;
int n,m,a[N][N],c[N],mx,ans=INF,p[N];

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}

int main(void)
{
	read(n),read(m);
	rep(i,1,n)rep(j,1,m)read(a[i][j]);
	rep(i,1,n)c[a[i][p[i]=1]]++;
	rep(i,1,m)
	{
		mx=0;
		rep(i,1,m)if(c[mx]<c[i])mx=i;
		ans=min(ans,c[mx]);
		c[mx]=0;
		killed[mx]=true;
		rep(i,1,n)
		{
			c[a[i][p[i]]]--;
			while(killed[a[i][p[i]]])p[i]++;
			c[a[i][p[i]]]++;
		}
	}
	printf("%d",ans);
	return 0;
}
