#include <bits/stdc++.h>
using namespace std;
const int MAXN = 512;
const int INF = 1000 * 1000 * 1000;
int n, m, a[MAXN][MAXN], s[MAXN][MAXN], ans = -INF;
int sum(int i, int j, int l) {
  return s[i + l - 1][j + l - 1] - s[i + l - 1][j - 1] - s[i - 1][j + l - 1] +
         s[i - 1][j - 1];
}
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)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      int curi = i, curj = j, curs = a[i + 1][j] + a[i + 1][j + 1];
      for (int l = 3;
           curi >= 1 && curj >= 1 && curi + l - 1 <= n && curj + l - 1 <= m;
           l += 2) {
        ans = max(ans, sum(curi, curj, l) - curs);
        curs = sum(curi, curj, l) - curs + a[curi][curj - 1];
        --curi;
        --curj;
      }
    }
  cout << ans;
  return 0;
}
