# 1479 Matrix Eraser import numpy as np from sys import stdin readline=stdin.readline h,w=map(int,readline().split()) A=np.array([list(map(int,readline().split()))]) for _ in range(1,h): A=np.append(A,np.array([list(map(int,readline().split()))]),axis=0) cnt=0 while True: maxA=np.max(A) if maxA==0: break atMaxA=np.where(A==maxA) rowBinCnt=np.bincount(atMaxA[0]) colBinCnt=np.bincount(atMaxA[1]) rowBinCntMax=np.max(rowBinCnt) colBinCntMax=np.max(colBinCnt) if rowBinCntMax>=colBinCntMax: selectedRow=np.where(rowBinCnt==rowBinCntMax)[0][0] A[selectedRow]=np.where(A[selectedRow]==maxA,0,A[selectedRow]) else: selectedCol=np.where(colBinCnt==colBinCntMax)[0][0] A[:,selectedCol]=np.where(A[:,selectedCol]==maxA,0,A[:,selectedCol]) cnt+=1 print(cnt)