H, W = map(int, input().split()) S = [] for i in range(H): for j, a in enumerate(list(map(int, input().split()))): if a > 0: S.append((a, i, j)) S.sort(reverse=True) cnt = 0 while len(S) > 0: a, i, j = S.pop(0) ai = [] aj = [] for b in S: if b[0] != a: break if i == b[1]: ai.append(b) elif j == b[2]: aj.append(b) for b in ai if len(ai) >= len(aj) else aj: S.remove(b) cnt += 1 print(cnt)