#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 300, MAX_M = 300;
int n, m;
int a[MAX_N][MAX_M];

int main()
{
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      cin >> a[i][j];

  vector<bool> valid(m, true);
  int min_q = INT_MAX;
  for (int i = 0; i < m; i++) {
    vector<int> ctr(m, 0);
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        if (valid[a[j][k]-1]) {
          ctr[a[j][k]-1]++;
          break;
        }
      }
    }
    int mi = max_element(ctr.begin(), ctr.end()) - ctr.begin();
    min_q = min(min_q, ctr[mi]);
    valid[mi] = false;
  }

  cout << min_q << endl;

  return 0;
}
