#include<cstdio>
#include<algorithm>
#include<cstring>

const int N = 305;

int n, m, pm[N][N], dt[N], num[N], now[N];
bool used[N];

int main () {
	scanf("%d%d", &n, &m); int ans = n;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) scanf("%d", &pm[i][j]);
		++num[pm[i][now[i] = 1]];
	}
	while (1) {
		int id = -1;
		for (int j = 1; j <= m; ++j) if (!used[j] && (id == -1 || num[j] > id)) id = num[j];
		if (id == -1) break ;
		if (id < ans) ans = id;
		for (int j = 1; j <= m; ++j) if (!used[j] && num[j] == id) used[j] = 1;
		for (int j = 1; j <= n; ++j) if (used[pm[j][now[j]]]) {
			while (used[pm[j][now[j]]]) ++now[j];
			++num[pm[j][now[j]]];
		}
	}
	printf("%d\n", ans);
	return 0;
}