#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 5;
const long long MOD = 1e9 + 7;
long long sum[maxn][maxn], v[maxn][maxn];
long long dp[maxn][maxn][2];
long long mat(int x1, int y1, int x2, int y2) {
  return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%lld", &v[i][j]);
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + v[i][j];
    }
  }
  long long ans = -1e18;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j + 1 <= m; j++) {
      dp[i][j][0] = v[i][j];
    }
  }
  for (int k = 3, p = 1; k <= min(n, m); k += 2, p ^= 1) {
    for (int i = 1; i <= n; i++) {
      if (i + k - 1 > n) break;
      for (int j = 1; j <= m; j++) {
        if (j + k - 1 > m) break;
        dp[i][j][p] = mat(i, j, i + k - 1, j + k - 1) -
                      dp[i + 1][j + 1][p ^ 1] - v[i + 1][j];
        ans = max(dp[i][j][p], ans);
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
