#include "iostream"
using namespace std;
int main(){
int m , n;
bool update;
cin >> m >> n;
int a[10000];
int len = 0 , count = 0;
len = m * n;
for(int i = 0; i < (m * n) ; i ++){
cin >> a[i];
count += a[i];
}
if(len > 4){
update = true;
}else{
update = false;
}
int errors = 0;
if(update){
for(int i = n + 1 ; i < (m * n - 1) - n ; i ++){
for(int j = i ; j < i + (n - 2) ; j ++){
errors += a[j];
}
i += n;
}
cout << count - errors;
}else{
int total = 0;
for(int i = 0; i < m * n ; i ++){
total += a[i];
}
cout << total;
}
return 0;
}