#include <bits/stdc++.h>
using namespace std;
const static int inf = 10000000;
const static int mod = 1000000007;
int n, m;
int a[500][500];
int sum[501][501];
int espiral[501][501];
int solve() {
  memset(sum, 0, sizeof(sum));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      sum[i][j] =
          sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i - 1][j - 1];
    }
  }
  const char* shape[3] = {"xxx", "..x", "xxx"};
  int maxFound = -500 * 500 * 1000;
  for (int i = 0; i + 3 <= n; i++) {
    for (int j = 0; j + 3 <= m; j++) {
      espiral[i][j] = 0;
      for (int x = 0; (x < 3) && (i + x < n); x++) {
        for (int y = 0; (y < 3) && (j + y < m); y++) {
          if (shape[x][y] == 'x') {
            espiral[i][j] += a[i + x][j + y];
          }
        }
      }
      maxFound = std::max(maxFound, espiral[i][j]);
    }
  }
  for (int k = 5; (k <= n) && (k <= m); k += 2) {
    for (int i = 0; i + k <= n; i++) {
      for (int j = 0; j + k <= m; j++) {
        int spir =
            sum[i + k][j + k] - sum[i + k][j] - sum[i][j + k] + sum[i][j];
        spir -= espiral[i + 1][j + 1];
        spir -= a[i + 1][j];
        espiral[i][j] = spir;
        maxFound = std::max(maxFound, spir);
      }
    }
  }
  return maxFound;
}
int main() {
  while (cin >> n >> m) {
    memset(a, 0, sizeof(a));
    for (int i = 0; i < (int)(n); i++) {
      for (int j = 0; j < (int)(m); j++) {
        cin >> a[i][j];
      }
    }
    cout << solve() << endl;
  }
}
