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