#include <bits/stdc++.h>
int H, W, a[212][212];
int ans = 0;
int main(void) {
  scanf("%d%d", &H, &W);
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      ans += a[i][j];
    }
  }
  if (3 == H) {
    for (int i = 0; i <= W - 3; ++i) {
      ans -= std::min(a[i][2], std::min(a[i + 1][1], a[i + 2][0]));
    }
  }
  printf("%d\n", ans);
  return 0;
}
