#include <bits/stdc++.h>
using namespace std;
unsigned long long mod = 1e9 + 7;
long long n, m, ans, rw[100005], cl[100005];
int main() {
  cin >> n >> m;
  long long a[n + 5][m + 5];
  long long b[n + 5][m + 5];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  for (int k = 0; k < 16; k++) {
    memset(rw, 0, sizeof rw);
    memset(cl, 0, sizeof cl);
    long long ans1 = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        rw[i] += a[i][j];
        cl[j] += a[i][j];
        b[i][j] = a[i][j];
      }
    }
    for (int z = 0; z < 4; z++) {
      if ((k & (1 << z))) {
        long long mx = -1, id = 0;
        for (int i = 0; i < n; i++) {
          if (rw[i] > mx) {
            mx = rw[i];
            id = i;
          }
        }
        ans1 += mx;
        rw[id] = 0;
        for (int j = 0; j < m; j++) {
          cl[j] -= b[id][j];
          b[id][j] = 0;
        }
      } else {
        long long mx = -1, id = 0;
        for (int i = 0; i < m; i++) {
          if (cl[i] > mx) {
            mx = cl[i];
            id = i;
          }
        }
        ans1 += mx;
        cl[id] = 0;
        for (int j = 0; j < n; j++) {
          rw[j] -= b[j][id];
          b[j][id] = 0;
        }
      }
    }
    ans = max(ans, ans1);
  }
  cout << ans;
}
