#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
int n, m, ans;
int a[MAXN][MAXN], s[MAXN][MAXN];
int Cal(int x, int y, int r) {
  return s[x + r][y + r] - s[x - r - 1][y + r] - s[x + r][y - r - 1] +
         s[x - r - 1][y - r - 1];
}
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)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
  ans = -1e9;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      int dp = a[i][j];
      for (int r = 1; r <= n; ++r) {
        if (i - r < 1 || i + r > n || j - r < 1 || j + r > m) break;
        dp = Cal(i, j, r) - dp - a[i - r + 1][j - r];
        ans = max(ans, dp);
      }
    }
  printf("%d\n", ans);
  return 0;
}
