#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << a;
  cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << ' ';
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << ' ';
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << ' ';
  pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
  for (int i = (int)(0); i < (int)(n); i++) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << '\n';
}
long long check(long long n, long long m, long long x, long long y) {
  return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1000000007, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
                dy[4] = {0, 1, 0, -1};
long long a[222][222], b[222][222], dp[222][222];
void Main() {
  long long n, m;
  cin >> n >> m;
  if (n > 7) return;
  for (int i = (int)(0); i < (int)(n); i++)
    for (int j = (int)(0); j < (int)(m); j++) cin >> a[i][j];
  vector<long long> c(n + m);
  for (int i = (int)(0); i < (int)(n + m); i++) c[i] = i >= n;
  long long ans = 0;
  do {
    for (int i = (int)(0); i < (int)(n); i++)
      for (int j = (int)(0); j < (int)(m); j++) b[i][j] = a[i][j];
    long long x = 0, y = 0, sum = 0;
    sum += b[0][0];
    b[0][0] = 0;
    for (int i = (int)(0); i < (int)(n + m); i++) {
      if (!c[i])
        x++;
      else
        y++;
      sum += b[x][y];
      b[x][y] = 0;
    }
    memset(dp, 0, sizeof(dp));
    for (int i = (int)(1); i < (int)(n + 1); i++) {
      for (int j = (int)(1); j < (int)(m + 1); j++) {
        dp[i][j] =
            max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]) + b[i - 1][j - 1]);
      }
    }
    ans = max(ans, sum + dp[n][m]);
  } while (next_permutation((c).begin(), (c).end()));
  pr(ans);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  Main();
  return 0;
}
