#include using namespace std; using ll = long long; #define rep(i, n) for (int i=0; i<(int)(n); ++(i)) #define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i)) #define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i)) #define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i)) #define all(x) (x).begin(), (x).end() int main() { int h, w; cin >> h >> w; map>> aval; rep(i, h) rep(j, w) { int ai; cin >> ai; aval[ai].emplace_back(i, j); } int res = 0; for (auto itr=aval.rbegin(); itr!=aval.rend(); ++itr) { if (itr->first == 0) continue; map hcnt, wcnt; rep(i, (int)(itr->second.size())) { hcnt[itr->second[i].first]++; wcnt[itr->second[i].second]++; } res += min((int)(hcnt.size()), (int)(wcnt.size())); } cout << res << endl; return 0; }