#include <bits/stdc++.h>
using namespace std;
int main() {
  long long sum = 0, ans1 = 0, ans2 = 0, result = 0, real = 0;
  int n, m, maxrow = 0, maxcol = 0;
  cin >> n >> m;
  int arr[n][m], copy[n][m];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> copy[i][j];
  if (n <= 4 || m <= 4) {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) result += copy[i][j];
    cout << result;
    return 0;
  }
  result = 0;
  int p = 5, R = 4, C = 0;
  long long ans = 0;
  while (p--) {
    ans1 = ans2 = -1;
    int q = 4, row = 0, col = 0;
    result = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) arr[i][j] = copy[i][j];
    while (q--) {
      if (row < R) {
        ans1 = -1;
        for (int i = 0; i < n; i++) {
          sum = 0;
          for (int j = 0; j < m; j++) sum += arr[i][j];
          if (sum > ans1) {
            ans1 = sum;
            maxrow = i;
          }
        }
        for (int i = 0; i < m; i++) arr[maxrow][i] = 0;
        row++;
        result += ans1;
      }
      if (col < C) {
        ans2 = -1;
        for (int i = 0; i < m; i++) {
          sum = 0;
          for (int j = 0; j < n; j++) sum += arr[j][i];
          if (sum > ans2) {
            ans2 = sum;
            maxcol = i;
          }
        }
        for (int i = 0; i < n; i++) arr[i][maxcol] = 0;
        result += ans2;
        col++;
      }
    }
    R--;
    C++;
    ans = max(ans, result);
  }
  cout << ans;
  return 0;
}
