#include <bits/stdc++.h>
using namespace std;
set<int> v[100009];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long int mi = INT_MAX, ma = INT_MIN, gcd, i, j, k, w, d, x, y, x1, y1, p,
                q, r, n, m, root, t;
  cin >> n >> m;
  long long int sum[n], sum1[m], a[n][m];
  memset(sum, 0, sizeof(sum));
  memset(sum1, 0, sizeof(sum1));
  for (i = 0; i < n; i++)
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      sum[i] += a[i][j];
      sum1[j] += a[i][j];
    }
  long long int tem1[n], tem2[m];
  long long int ans = 0;
  for (r = 0; r < 16; r++) {
    for (i = 0; i < n; i++) tem1[i] = sum[i];
    for (i = 0; i < m; i++) tem2[i] = sum1[i];
    x = 0;
    for (q = 0; q < 4; q++) {
      if ((1 << q) & r) {
        j = 0;
        for (i = 1; i < n; i++)
          if (tem1[i] > tem1[j]) j = i;
        x += tem1[j];
        tem1[j] = 0;
        for (p = 0; p < m; p++) tem2[p] -= a[j][p];
      } else {
        j = 0;
        for (i = 1; i < m; i++)
          if (tem2[i] > tem2[j]) j = i;
        x += tem2[j];
        tem2[j] = 0;
        for (p = 0; p < n; p++) tem1[p] -= a[p][j];
      }
    }
    ans = max(ans, x);
  }
  cout << ans;
  return 0;
}
