h, w = map(int, input().split()) a = [list(map(int, input().split())) for i in range(h)] m_row = dict() m_column = dict() for i in range(h): for j in range(w): if a[i][j] not in m_row: m_row[a[i][j]] = set() if a[i][j] not in m_column: m_column[a[i][j]] = set() m_row[a[i][j]].add(i) m_column[a[i][j]].add(j) ans = 0 for i in m_row: if i == 0: continue ans += min(len(m_row[i]), len(m_column[i])) print(ans)