using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { var HW = ReadLine().Split(); var H = int.Parse(HW[0]); var W = int.Parse(HW[1]); var map = new bool[H, W]; var zero = 0; for (int i = 0; i < H; i++) { var line = ReadLine(); for (int j = 0; j < W; j++) { if (line[j * 2] == '0') zero++; else map[i, j] = true; } } if (zero == 0) { WriteLine(1); return; } var ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (!map[i, j]) continue; var m = i * W + j; if (j != W - 1 && map[i, j + 1]) ans++; if (i != H - 1 && map[i + 1, j]) ans++; } } WriteLine(H * W - ans - zero); } }