#include <bits/stdc++.h>
using namespace std;
const int MAXN = 512;
long long sum[MAXN][MAXN], res[MAXN][MAXN];
int ar[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", &ar[i][j]);
      res[i][j] = ar[i][j];
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + ar[i][j];
    }
  }
  long long ans = -500000;
  for (int k = 3; k <= min(n, m); k += 2) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        if (i + k - 1 > n || j + k - 1 > m) break;
        int cur = sum[i + k - 1][j + k - 1] - sum[i - 1][j + k - 1] -
                  sum[i + k - 1][j - 1] + sum[i - 1][j - 1];
        res[i][j] = cur - res[i + 1][j + 1] - ar[i + 1][j];
        ans = max(ans, res[i][j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
