import java.util.*; public class No697{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); int ans = 0; int[][] a = new int[H+2][W+2]; Arrays.fill(a[0], 0); Arrays.fill(a[H+1], 0); for(int h = 1; h < H+1; h++){ Arrays.fill(a[h], 0); for(int w = 1; w < W+1; w++){ a[h][w] = sc.nextInt(); if(a[h][w] == 1 && (a[h][w-1]==0 && a[h-1][w]==0)){ ans++; } } } for(int h = 2; h < H+1; h++){ for(int w = 2; w < W+1; w++){ if(a[h][w] == 1 && (a[h][w-1]==0 && a[h-1][w]==0 && (a[h][w+1]==1 || a[h+1][w]==1))){ ans--; } } } System.out.println(ans); } }