#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int N = 305;
int pos[N], vis[N], a[N][N], cnt[N];
int n, m;

int dfs(int s){
  memset(cnt, 0, sizeof(cnt));
  int ans = 0, mpos = -1;
  for(int i = 0; i < n; i++){
    while(vis[a[i][pos[i]]]) pos[i]++;
    cnt[a[i][pos[i]]]++;
  }
  for(int i = 1; i <= m; i++)
    if(!vis[i] && cnt[i] > ans){
      ans = cnt[i];
      mpos = i;
    }
  vis[mpos] = 1;
  if(ans == ceil(1.0 * n / s))  return ans;
  else return min(ans, dfs(s-1));
}

int main()
{
  scanf("%d%d", &n, &m);
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
      scanf("%d", &a[i][j]);
  int ans = dfs(m);
  printf("%d\n", ans);
  return 0;
}
