#include <bits/stdc++.h>
using namespace std;
vector<long long> ini[101000];
long long h[101000], l[101000];
int main() {
  int i, j, k, n, m;
  long long t, ans1 = 0, ans2 = 0, ans = 0;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    ini[i].push_back(0);
    for (j = 1; j <= m; j++) {
      scanf("%lld", &t);
      h[i] += t, l[j] += t;
      ini[i].push_back(t);
    }
  }
  for (i = 1; i <= n; i++) {
    t = h[i];
    priority_queue<long long> q;
    for (j = 1; j <= m; j++) q.push(l[j] - ini[i][j]);
    for (j = 1; j <= 3 && q.size(); j++) t += q.top(), q.pop();
    ans = max(ans, t);
  }
  for (i = 1; i <= m; i++) {
    t = l[i];
    priority_queue<long long> q;
    for (j = 1; j <= n; j++) q.push(h[j] - ini[j][i]);
    for (j = 1; j <= 3 && q.size(); j++) t += q.top(), q.pop();
    ans = max(ans, t);
  }
  if (min(n, m) >= 2)
    for (i = 1; i <= n - 1; i++) {
      for (j = i + 1; j <= n; j++) {
        t = h[i] + h[j];
        priority_queue<long long> q;
        for (k = 1; k <= m; k++) q.push(l[k] - ini[i][k] - ini[j][k]);
        for (k = 1; k <= 2 && q.size(); k++) t += q.top(), q.pop();
        ans = max(ans, t);
      }
    }
  sort(h + 1, h + 1 + n, greater<long long>());
  sort(l + 1, l + 1 + m, greater<long long>());
  for (int i = 1; i <= 4; i++) ans1 += h[i], ans2 += l[i];
  ans = max(ans, max(ans1, ans2));
  printf("%lld\n", ans);
}
