import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int h = sc.nextInt(); int w = sc.nextInt(); ArrayList> rows = new ArrayList<>(); ArrayList> cols = new ArrayList<>(); for (int i = 0; i < w; i++) { cols.add(new HashMap<>()); } for (int i = 0; i < h; i++) { rows.add(new HashMap<>()); for (int j = 0; j < w; j++) { int x = sc.nextInt(); if (x == 0) { continue; } rows.get(i).put(x, rows.get(i).getOrDefault(x, 0) + 1); cols.get(j).put(x, cols.get(j).getOrDefault(x, 0) + 1); } } TreeMap> all = new TreeMap<>(); for (int i = 0; i < h; i++) { for (Map.Entry entry : rows.get(i).entrySet()) { int key = entry.getKey(); int value = entry.getValue(); if (!all.containsKey(-key)) { all.put(-key, new PriorityQueue<>()); } all.get(-key).add(new Unit(value, true)); } } for (int i = 0; i < w; i++) { for (Map.Entry entry : cols.get(i).entrySet()) { int key = entry.getKey(); int value = entry.getValue(); if (!all.containsKey(-key)) { all.put(-key, new PriorityQueue<>()); } all.get(-key).add(new Unit(value, false)); } } int ans = 0; for (PriorityQueue queue : all.values()) { int rowCount = 0; int colCount = 0; while (queue.size() > 0) { Unit u = queue.poll(); if (u.isRow) { if (u.value > colCount) { ans++; rowCount++; } } else { if (u.value > rowCount) { ans++; colCount++; } } } } System.out.println(ans); } static class Unit implements Comparable { int value; boolean isRow; public Unit(int value, boolean isRow) { this.isRow = isRow; this.value = value; } public int compareTo(Unit another) { return another.value - value; } public String toString() { return value + ":" + isRow; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }