local mmi, mma = math.min, math.max
local n, m = io.read("*n", "*n")
local player = {}
local playerpos = {}
local removecnt = 0
local removed = {}
for i = 1, m do
  removed[i] = false
end
local mcnt = {}
for i = 1, n do
  player[i] = {}
  playerpos[i] = 1
  for j = 1, m do
    local v = io.read("*n")
    player[i][j] = v
  end
end
local maxscore = 0
local ret = n
local function calc()
  maxscore = 0
  for i = 1, m do
    mcnt[i] = 0
  end
  for i = 1, n do
    local v = player[i][playerpos[i]]
    mcnt[v] = mcnt[v] + 1
  end
  for i = 1, m do
    maxscore = mma(maxscore, mcnt[i])
  end
  ret = mmi(ret, maxscore)
end

local function remove()
  for i = 1, m do
    if mcnt[i] == maxscore then
      removed[i] = true
      removecnt = removecnt + 1
    end
  end
  if removecnt == m then
    print(ret)
    os.exit()
  end
  for i = 1, n do
    local pi = player[i]
    while removed[pi[playerpos[i]]] do
      playerpos[i] = playerpos[i] + 1
    end
  end
end
while true do
  calc()
  remove()
end
