#include <bits/stdc++.h>
using namespace std;
struct fastio {
  fastio() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(12);
    cout << fixed;
  }
} _____;
const long long INF = 1e9;
const int MAX = 1e5 + 10;
const long double EPS = 1e-8;
const long long mod = 1e9 + 7;
int n, m;
vector<vector<long long>> a;
long long sumx[100001];
long long sumy[100001];
int main() {
  cin >> n >> m;
  a.resize(n);
  for (int i = 0; i < n; i++) a[i].resize(m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) sumx[i] += a[i][j];
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) sumy[i] += a[j][i];
  vector<long long> x;
  vector<long long> y;
  for (int i = 0; i < n; i++) x.push_back(sumx[i]);
  for (int i = 0; i < m; i++) y.push_back(sumy[i]);
  sort(x.rbegin(), x.rend());
  sort(y.rbegin(), y.rend());
  long long maxx = -1;
  long long sum = 0;
  for (int i = 0; i < 4 && i < x.size(); i++) sum += x[i];
  maxx = max(maxx, sum);
  sum = 0;
  for (int i = 0; i < 4 && i < y.size(); i++) sum += y[i];
  maxx = max(maxx, sum);
  int maxnum = -1;
  long long maxans = -1;
  for (int i = 0; i < n; i++) {
    y.clear();
    for (int j = 0; j < m; j++) y.push_back(sumy[j] - a[i][j]);
    sort(y.rbegin(), y.rend());
    long long sum = sumx[i];
    for (int i = 0; i < 3 && i < y.size(); i++) sum += y[i];
    if (maxans < sum) {
      maxans = sum;
      maxnum = i;
    }
  }
  maxx = max(maxx, maxans);
  for (int i = 0; i < n; i++)
    if (i != maxnum) {
      y.clear();
      for (int j = 0; j < m; j++) y.push_back(sumy[j] - a[i][j] - a[maxnum][j]);
      sort(y.rbegin(), y.rend());
      long long sum = sumx[i] + sumx[maxnum];
      for (int i = 0; i < 2 && i < y.size(); i++) sum += y[i];
      maxx = max(maxx, sum);
    }
  maxnum = -1;
  maxans = -1;
  for (int i = 0; i < m; i++) {
    x.clear();
    for (int j = 0; j < n; j++) x.push_back(sumx[j] - a[j][i]);
    sort(x.rbegin(), x.rend());
    long long sum = sumy[i];
    for (int i = 0; i < 3 && i < x.size(); i++) sum += x[i];
    if (maxans < sum) {
      maxans = sum;
      maxnum = i;
    }
  }
  for (int i = 0; i < m; i++)
    if (i != maxnum) {
      x.clear();
      for (int j = 0; j < n; j++) x.push_back(sumx[j] - a[j][i] - a[j][maxnum]);
      sort(x.rbegin(), x.rend());
      long long sum = sumy[i] + sumy[maxnum];
      for (int i = 0; i < 2 && i < x.size(); i++) sum += x[i];
      maxx = max(maxx, sum);
    }
  cout << maxx;
  return 0;
}
