#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;

int n, m, p[MAXN][MAXN], cur[MAXN], tot, ans, cnt[MAXN];
bool used[MAXN];

int main(){
	int i, j, mx;
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; ++ i)
		for(j = 1; j <= m; ++ j)
			scanf("%d", &p[i][j]);
	for(i = 1; i <= n; ++ i)
		cur[i] = 1;
	for(i = 1; i <= m; ++ i)
		used[i] = true;
	tot = m, ans = n;
	while(tot){
		memset(cnt, 0, sizeof(cnt));
		for(i = 1; i <= n; ++ i){
			while(!used[p[i][cur[i]]]) ++ cur[i];
			++ cnt[p[i][cur[i]]];
		}
		for(i = 1, mx = 0; i <= m; ++ i)
			if(cnt[i] > mx) mx = cnt[i];
		if(mx < ans) ans = mx;
		for(i = 1; i <= m; ++ i)
			if(cnt[i] == mx) used[i] = false, -- tot;
	} printf("%d\n", ans);
	return 0;
}