#include <bits/stdc++.h>
using namespace std;
int row, column;
long long sums_row[100005], sums_column[100005];
long long result = 0;
int bit_row[5];
long long row_value[100005], column_value[100005];
int color_row[100005], color_column[100005];
int main() {
  scanf("%d %d", &row, &column);
  int table[row + 1][column + 1];
  for (int i = 1; i <= row; i++)
    for (int j = 1; j <= column; j++) scanf("%d", &table[i][j]);
  for (int i = 1; i <= row; i++) {
    for (int j = 1; j <= column; j++) {
      sums_row[i] += table[i][j];
      sums_column[j] += table[i][j];
    }
  }
  for (int some = 0; some < 16; some++) {
    int value = some;
    for (int i = 1; i <= row; i++) color_row[i] = 0;
    for (int i = 1; i <= column; i++) color_column[i] = 0;
    for (int i = 1; i <= 4; i++) {
      bit_row[i] = value % 2;
      value /= 2;
    }
    for (int i = 1; i <= row; i++) row_value[i] = sums_row[i];
    for (int i = 1; i <= column; i++) column_value[i] = sums_column[i];
    long long result_now = 0;
    for (int tester = 1; tester <= 4; tester++) {
      if (bit_row[tester]) {
        long long max_now = 0;
        int spot;
        for (int i = 1; i <= row; i++) {
          if (color_row[i] == 0 && row_value[i] > max_now) {
            max_now = row_value[i];
            spot = i;
          }
        }
        result_now += max_now;
        for (int i = 1; i <= column; i++) {
          column_value[i] -= table[spot][i];
        }
        color_row[spot] = 1;
      } else {
        long long max_now = 0;
        int spot;
        for (int i = 1; i <= column; i++) {
          if (color_column[i] == 0 && max_now < column_value[i]) {
            max_now = column_value[i];
            spot = i;
          }
        }
        result_now += max_now;
        color_column[spot] = 1;
        for (int i = 1; i <= row; i++) {
          row_value[i] -= table[i][spot];
        }
      }
    }
    result = max(result, result_now);
  }
  printf("%lld", result);
}
