#include <bits/stdc++.h>
using namespace std;
const int maxn = 502;
int d[maxn][maxn], dd[maxn][maxn], ddd[maxn][maxn][252], a[maxn][maxn], n, m,
    ans = -1000000000;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      d[i][j] = d[i][j - 1] + a[i][j];
      ddd[i][j][0] = a[i][j];
    }
  for (int j = 1; j <= m; j++)
    for (int i = 1; i <= n; i++) dd[i][j] = dd[i - 1][j] + d[i][j];
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--)
      for (int t = 1; t * 2 + 1 <= min(n, m); t++) {
        int tt = 2 * t + 1;
        if (i + tt > n + 1 | j + tt > m + 1) break;
        ddd[i][j][t] = dd[i - 1][j - 1] + dd[i + tt - 1][j + tt - 1] -
                       dd[i - 1][j + tt - 1] - dd[i + tt - 1][j - 1];
        ddd[i][j][t] += -ddd[i + 1][j + 1][t - 1] - a[i + 1][j];
        ans = max(ans, ddd[i][j][t]);
      }
  cout << ans << endl;
  return 0;
}
