#include <bits/stdc++.h>
using namespace std;

int a[305][305];
int del[305], pos[305], cnt[305];

int main(){
	int n, m, ans, maxx, rem;
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= m; j++){
			scanf("%d",&a[i][j]);
		}
	}
	memset(del, 0, sizeof(del));
	ans = n; rem = m;
	for (int i = 1; i <= n; i++) pos[i] = 1;
	while (true){
		memset(cnt, 0, sizeof(cnt));
		for (int i = 1; i <= n; i++) cnt[a[i][pos[i]]]++;
		maxx = 1;
		for (int i = 2; i <= m; i++){
			if (cnt[i] > cnt[maxx]) maxx = i;
		}
		ans = min(ans, cnt[maxx]);
		if (--rem == 0) break;
		del[maxx] = 1;
		for (int i = 1; i <= n; i++){
			if (a[i][pos[i]] == maxx){
				while (del[a[i][pos[i]]]) pos[i]++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
} 