#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
int a[maxn][maxn], dp[maxn][maxn][2], sum[maxn][maxn];
int main() {
  int n, m;
  while (scanf("%d %d", &n, &m) == 2) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++)
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) dp[i][j][0] = a[i][j];
    int now = 1, pre = 0;
    int ans = -(1 << 30);
    for (int k = 3; k <= n && k <= m; k += 2) {
      for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
          if (i + k - 1 <= n && j + k - 1 <= m) {
            dp[i][j][now] = sum[i + k - 1][j + k - 1] - sum[i - 1][j + k - 1] -
                            sum[i + k - 1][j - 1] + sum[i - 1][j - 1] -
                            dp[i + 1][j + 1][pre] - a[i + 1][j];
            if (dp[i][j][now] > ans) ans = dp[i][j][now];
          }
      now ^= 1;
      pre ^= 1;
    }
    printf("%d\n", ans);
  }
}
