#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<list<int>> v(N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      int a;
      cin >> a;
      v[i].push_back(a);
    }
  }
  int ans = 1e9;
  for (int i = M; i > 0; --i) {
    unordered_map<int, int> mp;
    for (int j = 0; j < N; ++j) {
      mp[v[j].front()]++;
    }
    int pre = 0, rem = 0;
    for (auto p : mp) {
      if (p.second > pre) {
        rem = p.first;
        pre = p.second;
      }
    }
    for (int j = 0; j < N; ++j) {
      v[j].remove_if([=](const int &x) { return x == rem; });
    }
    ans = min(ans, pre);
  }
  cout << ans << endl;
}