#include <bits/stdc++.h>
using namespace std;
long long n, m, a[502][502], pre[502][502], val[502][502];
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) cin >> a[i][j], val[i][j] = a[i][j];
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++)
      pre[i][j] =
          pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1] + a[i - 1][j - 1];
  }
  long long ans = -1e10;
  for (long long k = 3; k <= n && k <= m; k += 2) {
    for (long long i = 0; i <= n - k; i++) {
      for (long long j = 0; j <= m - k; j++) {
        val[i][j] = pre[i + k][j + k] - pre[i + k][j] - pre[i][j + k] +
                    pre[i][j] - val[i + 1][j + 1] - a[i + 1][j];
        ans = max(ans, val[i][j]);
      }
    }
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
