using System; using System.Collections.Generic; using System.Linq; class D { static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); static (int, int) Read2() { var a = Read(); return (a[0], a[1]); } static void Main() { var (h, w) = Read2(); var a = Array.ConvertAll(new bool[h], _ => Read()); var d = new Dictionary r, HashSet c)>(); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { var k = a[i][j]; if (k == 0) continue; if (!d.ContainsKey(k)) d[k] = (new HashSet(), new HashSet()); d[k].r.Add(i); d[k].c.Add(j); } } Console.WriteLine(d.Values.Sum(t => (long)Math.Min(t.r.Count, t.c.Count))); } }