#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T Abs(const T& value) {
  return value < 0 ? -value : value;
}
inline double Sqr(const double& value) { return value * value; }
template <typename T>
inline T Vm(const T& gjigu, const T& djigd, const T& x2, const T& y2) {
  return gjigu * y2 - x2 * djigd;
}
template <typename T>
inline T Sm(const T& gjigu, const T& djigd, const T& x2, const T& y2) {
  return gjigu * x2 + y2 * djigd;
}
const int maxn = 510;
int a[maxn][maxn];
int s[maxn][maxn];
int h[maxn][maxn];
int p[maxn][maxn];
inline int Get(int y, int x, int k) {
  return s[y][x] - s[y - k][x] - s[y][x - k] + s[y - k][x - k];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      s[i][j] = a[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
    }
  int mx = -2000000000;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      if (i >= 3 && j >= 3) {
        p[i][j] = Get(i, j, 3) - a[i - 1][j - 1] - a[i - 1][j - 2];
        if (p[i][j] >= mx) {
          mx = p[i][j];
        }
      }
    }
  for (int k = 5; k <= n && k <= m; k += 2) {
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        if (i >= k && j >= k) {
          h[i][j] = Get(i, j, k) - p[i - 1][j - 1] - a[i - k + 2][j - k + 1];
          if (h[i][j] > mx) {
            mx = h[i][j];
          }
        }
      }
    memcpy(p, h, sizeof(h));
  }
  cout << mx << endl;
  return 0;
}
