#include <bits/stdc++.h>
using namespace std;
const int maxn = 500 + 10;
int n, m, val[maxn][maxn], mat[maxn][maxn], dp[2][maxn][maxn], cur;
void init() {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) dp[cur][i][j] = -(1 << 30);
}
int main(int argc, char *argv[]) {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &val[i][j]);
      dp[cur][i][j] = val[i][j];
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      mat[i][j] = mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1] + val[i][j];
  int ans = -(1 << 30);
  for (int k = 1; k * 2 + 1 <= max(n, m); ++k) {
    int d = k * 2, pre = cur;
    cur ^= 1;
    init();
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j)
        if (i + d <= n && j + d <= m) {
          int x1 = i, y1 = j, x2 = x1 + 2 * k, y2 = y1 + 2 * k;
          dp[cur][i][j] = mat[x2][y2] + mat[x1 - 1][y1 - 1] - mat[x2][y1 - 1] -
                          mat[x1 - 1][y2] - val[i + 1][j] -
                          dp[pre][i + 1][j + 1];
          ans = max(ans, dp[cur][i][j]);
        }
  }
  printf("%d\n", ans);
  return 0;
}
