import java.util.*;/*** @author 308413* @version Ver 1.0* @date 2025/6/18* @description 返回矩陣中非1的元素*/
public class Non1ElementInMatrix {public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int N = scanner.nextInt();int M = scanner.nextInt();int[][] matrix = new int[N][M];for (int i = 0; i < N; i++) {for (int j = 0; j < M; j++) {matrix[i][j] = scanner.nextInt();}}solve(matrix,N,M);}private static void solve(int[][] matrix, int n, int m) {LinkedList<int[]> queue = new LinkedList<>();int[][] directions = new int[][]{{0,1},{1,0},{0,-1},{-1,0}};//將矩陣中的0,0改為1,開始同化matrix[0][0]= 1;// 將起點0,0加入隊列queue.add(new int[]{0,0});while(!queue.isEmpty()){int[] ints = queue.poll();for(int i =0;i<4;i++){int x = ints[0]+directions[i][0];int y = ints[1]+directions[i][1];if(x>=0 && x<n && y>=0 && y<m && matrix[x][y]==0){matrix[x][y]=1;queue.add(new int[]{x,y});}}}
// for (int i = 0; i < n; i++) {
// for (int j = 0; j < m; j++) {
// System.out.print(matrix[i][j]+" ");
// }
// System.out.println();
// }int count = 0;for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if(matrix[i][j]!=1){count++;}}}System.out.println(count);}
}