#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
const double PI = 2 * acos(0.0);
const double EPS = 1e-8;
const int INF = (1 << 30) - 1;
int m, n, ans;
int a[500][500], cum[500][500];
int d[2][500][500];
inline int getsq(int r, int c, int s) {
  return cum[r + s - 1][c + s - 1] - (r == 0 ? 0 : cum[r - 1][c + s - 1]) -
         (c == 0 ? 0 : cum[r + s - 1][c - 1]) +
         (r == 0 || c == 0 ? 0 : cum[r - 1][c - 1]);
}
int main() {
  scanf("%d%d", &m, &n);
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < n; ++j) scanf("%d", &a[i][j]);
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < n; ++j) {
      cum[i][j] = (i == 0 ? 0 : cum[i - 1][j]) + (j == 0 ? 0 : cum[i][j - 1]) -
                  (i == 0 || j == 0 ? 0 : cum[i - 1][j - 1]) + a[i][j];
    }
  ans = -INF;
  for (int i = 0; i < m - 2; ++i)
    for (int j = 0; j < n - 2; ++j) {
      d[0][i][j] = getsq(i, j, 3) - a[i + 1][j] - a[i + 1][j + 1];
      ans = (ans > d[0][i][j] ? ans : d[0][i][j]);
    }
  int t = 1;
  for (int s = 5; s <= (m < n ? m : n); s += 2) {
    for (int i = 0; i < m - s + 1; ++i)
      for (int j = 0; j < n - s + 1; ++j) {
        d[t][i][j] = getsq(i, j, s) - d[t ^ 1][i + 1][j + 1] - a[i + 1][j];
        ans = (ans > d[t][i][j] ? ans : d[t][i][j]);
      }
    t = t ^ 1;
  }
  cout << ans;
  return 0;
};
