#include <bits/stdc++.h>
using namespace std;
int ary[210][210];
int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> ary[i][j];
    }
  }
  int res = 0;
  if (H <= 3 && W <= 3) {
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        res += ary[i][j];
      }
    }
    if (H == 3 && W == 3) {
      res -= min(ary[1][3], min(ary[2][2], ary[3][1]));
    }
  }
  cout << res << endl;
  return 0;
}
