#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const long long INF = (long long)1e18 + 7;
vector<vector<long long>> a;
long long col[N], row[N], trow[N], tcol[N];
long long res;
int m, n;
long long getrow() {
  long long ma = trow[1];
  long long pos = 1;
  for (int i = 2; i <= m; i++)
    if (trow[i] > ma) {
      ma = trow[i];
      pos = i;
    }
  trow[pos] = 0;
  for (int i = 1; i <= n; i++) tcol[i] -= a[pos][i];
  return max(0ll, ma);
}
long long getcol() {
  long long ma = tcol[1];
  long long pos = 1;
  for (int i = 2; i <= n; i++)
    if (tcol[i] > ma) {
      ma = tcol[i];
      pos = i;
    }
  tcol[pos] = 0;
  for (int i = 1; i <= m; i++) trow[i] -= a[i][pos];
  return max(0ll, ma);
}
void sett() {
  for (int i = 1; i <= m; i++) trow[i] = row[i];
  for (int i = 1; i <= n; i++) tcol[i] = col[i];
}
void proces(int st, int nd, int rd, int th) {
  long long ma = 0;
  sett();
  if (st)
    ma += getcol();
  else
    ma += getrow();
  if (nd)
    ma += getcol();
  else
    ma += getrow();
  if (rd)
    ma += getcol();
  else
    ma += getrow();
  if (th)
    ma += getcol();
  else
    ma += getrow();
  res = max(res, ma);
}
int main() {
  cin >> m >> n;
  a.resize(m + 1);
  for (int i = 1; i <= m; i++) {
    a[i].push_back(0);
    long long t;
    for (int j = 1; j <= n; j++) {
      cin >> t;
      a[i].push_back(t);
    }
  }
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) row[i] += a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) col[i] += a[j][i];
  for (int a1 = 0; a1 <= 1; a1++)
    for (int a2 = 0; a2 <= 1; a2++)
      for (int a3 = 0; a3 <= 1; a3++)
        for (int a4 = 0; a4 <= 1; a4++) proces(a1, a2, a3, a4);
  cout << res;
}
