#include <bits/stdc++.h>

using namespace std;

#define llong long long 
#define len(v) ((int)v.size())
#define ii pair<int, int>
#define xx first
#define yy second
#define rep(i,n) for (int i = -1; ++i < n; )
#define rep1(i,n) for (int i = 0; ++i <= n;)

#define maxn 333
int n, m;
int a[maxn][maxn];

int fre[maxn];

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  rep(i, n) rep(f, m) cin >> a[i][f];

  int ans = maxn;
  rep(i, m) {
    ii t;
    rep(f, n)
      t = max(t, {++fre[a[f][0]], a[f][0]});
    ans = min(ans, t.xx);
    rep(f, n)
      remove(a[f], a[f] + m - i, t.yy);
    memset(fre, 0, sizeof(fre));
  }

  cout << ans;

  return 0;
}
