import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int M, N; scanf("%d %d\n", &M, &N);
    int[][] A = new int[][M];
    foreach (i; 0 .. M) {
        A[i] = readln.chomp.split(" ").map!(to!int).array;
    }

    const dy = [1, 0, -1, 0],
          dx = [0, 1, 0, -1];
    
    void eat(ulong y, ulong x) {
        A[y][x] = 2;
        foreach (i; 0 .. 4) {
            auto ny = y + dy[i],
                 nx = x + dx[i];
            if (ny < 0 || ny >= M) continue;
            if (nx < 0 || nx >= N) continue;
            if (A[ny][nx] == 2) continue;
            if (A[ny][nx] == 1) {
                A[ny][nx] = 0;
            } else {
                assert(A[ny][nx] == 0);
                A[ny][nx] = 1;
            }
        }
    }

    bool sweet(out ulong ey, out ulong ex) {
        foreach (y; 0 .. M) {
            foreach (x; 0 .. N) {
                if (A[y][x] != 1) continue;
                if (0 <= y - 1 && A[y - 1][x] != 2) continue;
                if ( (0 <= x - 1 && A[y][x - 1] != 2) &&
                     (x + 1 < N && A[y][x + 1] != 2) ) continue;
                ey = y; ex = x;
                return true;
            }
        }
        foreach (y; 0 .. M) {
            foreach (x; 0 .. M) {
                if (A[y][x] != 2) {
                    ey = y;
                    ex = x;
                    goto loopend;
                }
            }
        }
loopend: return false;
    }

    int C = 0;
    for (int _ = 0; _ < M * N; _++) {
        ulong y, x;
        if (sweet(y, x)) {
            C++;
            eat(y, x);
        } else {
            eat(y, x);
        }
    }
    writeln(C);
}