1 1 2 2
1000000000 1000000000
1
 1 1 1000000000 1000000000
100 1000000000
1
 1 1 10 18
5 6
5
 2 1 1000000000 2000000000
111 999999999
101 999999998
1
 4 13 400 600
13 30
1 19
1 160
1 113
58 73 15 319 194 362 128 157 336 162 77 90 96
 1 15 100 200
283 8
30 58 16 45 80 82 55 95 24 23 86 28 51 47 20
 3 2 300 400
24 68
13 65
15 113
127 177
 1 1 2 1
1 10
1
 4 2 7 15
10 9
4 4
9 3
4 10
1 6
 2 1 1000000000 2000000000
111 1000000000
101 1000000000
5
 2 1 1000000000 2000000000
111 999999998
101 999999998
1
 1 1 1000000000 1000000000
1 1000000000
1

1000000000
 -1
 5
 111
 1
 -1
 -1
 -1
 4
 101
 -1
 -1

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);
		short n = scn.nextShort();
		short m = scn.nextShort();
		short good = 0;

		byte[][] mass = new byte[n][m];

		for (short i = 0; i < n; i++) {

			Scanner scn2 = new Scanner(System.in);
			for (short j = 0; j < m; j++) {
				mass[i][j] = scn.nextByte();
			}

		}

		for (int i = 0; i < n; i++) {

			for (int j = 0; j < m; j++) {

				if (mass[i][j] == 0) {

					if (i != 0) {
						if (mass[i - 1][j] == 1)
							good++;
					}
					if (j != m - 1 ) {

						if( mass[i][j + 1] == 1)good++;

					} else if (i + 1 < n) {

						if(mass[i + 1][0] == 1)good++;

					}

					if (i != n - 1 )
						if( mass[i + 1][j] == 1)good++;

					if (j != 0  ) {

						if(mass[i][j - 1] == 1)good++;

					} else if (i- 1 > -1) {
						if(mass[i - 1][m - 1] == 1)
						good++;

					}

				}

			}

		}

		System.out.println(good);
	}
}