#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
int debug = 0;
char buf[128];
char buf2[128];
fgets(buf, 128, stdin);
char * x = buf;
int m = strtol(x, &x, 10);
x++;
int n = strtol(x, NULL, 10);
if (debug) fprintf(stderr, "m %d n %d\n", m, n);
char * old = buf;
char * cur = buf2;
memset(old, '0', 128);
memset(cur, '0', 128);
unsigned mej = 0;
while (!ferror(stdin) && !feof(stdin) && m--) {
fgets(cur, 128, stdin);
unsigned meja = 0;
for (int i = 0; i < n-1; i++)
if (cur[i] != cur[i+1])
meja++;
if (cur[n-1] == '1')
meja++;
if (cur[0] == '1')
meja++;
if (debug) fprintf(stderr, "vrsta. po ld je mej: %u\n", meja);
mej += meja;
meja = 0;
for (int i = 0; i < n; i++)
if (old[i] != cur[i])
meja++;
if (debug) fprintf(stderr, "\tpo gor dol je mej: %u\n", meja);
mej += meja;
meja = 0;
if (!m)
for (int i = 0; i < n; i++)
if (cur[i] == '1')
meja++;
if (debug) fprintf(stderr, "\tpo zadnji je mej: %u\n", meja);
mej += meja;
meja = 0;
char * tmp = old;
old = cur;
cur = tmp;
}
printf("%u\n", mej);
}