#include <bits/stdc++.h>
using namespace std;
const int nax = 2e5;
vector<vector<long long>> g;
long long row[nax], col[nax];
long long ans = 0;
int n, m;
void calc(long long cur, int idx) {
  if (idx == 4) {
    ans = max(ans, cur);
    return;
  }
  vector<pair<long long, int>> sum;
  for (int i = 0; i < n; i++) {
    sum.push_back({row[i], i});
  }
  for (int j = 0; j < m; j++) {
    sum.push_back({col[j], n + j});
  }
  sort(sum.begin(), sum.end());
  reverse(sum.begin(), sum.end());
  for (int x = 0; x < min(2, (int)sum.size()); x++) {
    long long mx = sum[x].first, at = sum[x].second;
    vector<vector<long long>> tmp = g;
    if (at < n) {
      for (int i = 0; i < m; i++) {
        row[at] -= g[at][i];
        col[i] -= g[at][i];
        g[at][i] = 0;
      }
    } else {
      for (int i = 0; i < n; i++) {
        row[i] -= g[i][at - n];
        col[at - n] -= g[i][at - n];
        g[i][at - n] = 0;
      }
    }
    calc(cur + mx, idx + 1);
    if (at < n) {
      for (int i = 0; i < m; i++) {
        g[at][i] = tmp[at][i];
        row[at] += g[at][i];
        col[i] += g[at][i];
      }
    } else {
      for (int i = 0; i < n; i++) {
        g[i][at - n] = tmp[i][at - n];
        row[i] += g[i][at - n];
        col[at - n] += g[i][at - n];
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  cin >> n >> m;
  g = vector<vector<long long>>(n, vector<long long>(m));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> g[i][j];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      row[i] += g[i][j];
      col[j] += g[i][j];
    }
  }
  calc(0, 0);
  cout << ans << endl;
}
