#include <bits/stdc++.h>
using namespace std;
const int maxn = 505;
int a[maxn][maxn], dp[maxn][maxn], sum[maxn][maxn];
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("%d", &a[i][j]);
      dp[i][j] = a[i][j];
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
    }
  }
  int ans = -1e9;
  for (int size = 3; size <= n && size <= m; size += 2) {
    for (int i = size, ii = 1; i <= n; i++, ii++) {
      for (int j = size, jj = 1; j <= m; j++, jj++) {
        dp[ii][jj] = sum[i][j] - sum[ii - 1][j] - sum[i][jj - 1] +
                     sum[ii - 1][jj - 1] - dp[ii + 1][jj + 1] - a[ii + 1][jj];
        if (ans < dp[ii][jj]) ans = dp[ii][jj];
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
