#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for (int i=1;i<=n;i++)
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define ll long long
const int N=300+10;
const int inf=0x3f3f3f3f;
const ll mod=1000000007;

int n,m;
int a[N][N];
int num[N];
bool v[N];
int ans;
int main() {
	//freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d%d",&n,&m);
    int s;
    FOR(i,n) {
    	FOR(j,m) scanf("%d",&a[i][j]);
		int b=a[i][1];
		if (++num[b]>ans) {
			ans=num[b];
			s=b;
		}
	}
	FOR(i,m-1) {
		memset(num,0,sizeof num);
		v[s]=1;
		int tans=0;
		FOR(j,n) {
			FOR(k,m) {
				int b=a[j][k];
				if (!v[b]) {
					if (++num[b]>tans) {
						tans=num[b];
						s=b;
					}
					break;
				}
			}
		}
		ans=min(ans,tans);
	}
	printf("%d",ans);
	return 0;
}