#include <bits/stdc++.h>
const int N = 510;
const int inf = 0x3f3f3f3f;
using namespace std;
int n, m;
int a[N][N], sum[N][N], spi[N][N];
int main() {
  scanf("%d%d", &n, &m);
  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++) spi[i][j] = a[i][j];
  int ret = -inf;
  for (int k = 2; k <= min(n, m); k += 2) {
    for (int i = 1; i + k <= n; i++)
      for (int j = 1; j + k <= m; j++) {
        spi[i][j] = sum[i + k][j + k] - sum[i + k][j - 1] - sum[i - 1][j + k] +
                    sum[i - 1][j - 1] - spi[i + 1][j + 1] - a[i + 1][j];
        ret = max(ret, spi[i][j]);
      }
  }
  printf("%d\n", ret);
  return 0;
}
