#include <iostream>
#include <cstdio>
using namespace std;

int n, m, mn = 2e9, mx, x, a[305][305], v[305], b[305], cnt[305];
int main()
{
	int i, j;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		for (j = 0; j < m; j++) {
			scanf ("%d", &a[i][j]);
		}
	}
	for (i = 1; i <= n; i++) {
		cnt[a[i][0]]++;
	}
	for (i = 0; i < m; i++) {
		mx = 0;
		for (j = 1; j <= m; j++) {
			if (cnt[j] > mx) {
				mx = cnt[j];
				x = j;
			}
		}
		mn = min(mn, mx);
		v[x] = 1;
		for (j = 1; j <= n; j++) {
			if (a[j][b[j]] != x) continue;
			for (b[j]++; b[j] < m && v[a[j][b[j]]]; b[j]++);
			cnt[x]--;
			cnt[a[j][b[j]]]++;
		}
	}
    cout << mn;
    return 0;
}
