#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T a) {
  return a * a;
}
const int maxn = 510;
int a[maxn][maxn];
int v[maxn][maxn];
int h[maxn][maxn];
int d[3][maxn][maxn];
int n, m;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  int best = -1000000000;
  for (int i = 0; i < n; i++)
    for (int j = 1; j <= m; j++) h[i][j] = h[i][j - 1] + a[i][j - 1];
  for (int i = 0; i < m; i++)
    for (int j = 1; j <= n; j++) v[i][j] = v[i][j - 1] + a[j - 1][i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) d[1][i][j] = a[i][j];
  for (int k = 3; k <= n && k <= m; k += 2) {
    if (k == 3) {
      for (int i = 0; i < n - k + 1; i++)
        for (int j = 0; j < m - k + 1; j++) {
          d[2][i][j] = a[i][j] + a[i][j + 1] + a[i][j + 2] + a[i + 1][j + 2] +
                       a[i + 2][j + 2] + a[i + 2][j + 1] + a[i + 2][j];
          best = max(best, d[2][i][j]);
        }
    } else {
      for (int i = 0; i < n - k + 1; i++)
        for (int j = 0; j < m - k + 1; j++) {
          d[2][i][j] = d[0][i + 2][j + 2] + a[i + 2][j + 1] + h[i][j + k] -
                       h[i][j] + h[i + k - 1][j + k] - h[i + k - 1][j] +
                       v[j][i + k - 1] - v[j][i + 2] + v[j + k - 1][i + k - 1] -
                       v[j + k - 1][i + 1];
          best = max(best, d[2][i][j]);
        }
    }
    memcpy(d[0], d[1], sizeof(d[0]));
    memcpy(d[1], d[2], sizeof(d[1]));
  }
  cout << best;
  return 0;
}
