#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int H = 200;
int a[H][H];
int main(void) {
  int h, w;
  cin >> h >> w;
  assert(h <= 3 && w <= 3);
  for (int i = (int)(0); i < (int)(h); i++) {
    for (int j = (int)(0); j < (int)(w); j++) {
      cin >> a[i][j];
    }
  }
  long long int tot = 0;
  for (int i = (int)(0); i < (int)(h); i++) {
    for (int j = (int)(0); j < (int)(w); j++) {
      tot += a[i][j];
    }
  }
  if (h <= 2 || w <= 2) {
    cout << tot << endl;
    return 0;
  }
  int mi = 1e9;
  for (int i = (int)(0); i < (int)(3); i++) {
    mi = min(mi, a[2 - i][i]);
  }
  cout << tot - mi << endl;
}
