#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000001;
const int nmax = 509;
int F[nmax / 2][nmax][nmax];
int n, m;
int Srow[nmax][nmax];
int Scol[nmax][nmax];
inline int suma(int i, int j, int k) {
  int ans = 0;
  ans += Srow[i][j + k - 1] - Srow[i][j] + F[1][i][j];
  ans += Srow[i + k - 1][j + k - 1] - Srow[i + k - 1][j] + F[1][i + k - 1][j];
  ans += Scol[j + k - 1][i + k - 2] - Scol[j + k - 1][i];
  ans += Scol[j][i + k - 2] - Scol[j][i + 1];
  ans += F[1][i + 2][j + 1];
  return ans;
}
int main() {
  scanf("%d %d", &n, &m);
  int ans = -inf;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &F[1][i][j]);
    }
  }
  for (int i = 0; i < n; ++i) {
    Srow[i][0] = F[1][i][0];
    for (int j = 1; j < m; ++j) {
      Srow[i][j] = Srow[i][j - 1] + F[1][i][j];
    }
  }
  for (int j = 0; j < m; ++j) {
    Scol[j][0] = F[1][0][j];
    for (int i = 1; i < n; ++i) {
      Scol[j][i] = Scol[j][i - 1] + F[1][i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (i + 2 < n && j + 2 < m) {
        F[2][i][j] = F[1][i][j] + F[1][i][j + 1] + F[1][i][j + 2] +
                     F[1][i + 1][j + 2] + F[1][i + 2][j] + F[1][i + 2][j + 1] +
                     F[1][i + 2][j + 2];
        ans = max(ans, F[2][i][j]);
      } else
        F[2][i][j] = -inf;
    }
  }
  for (int k = 5; k <= min(n, m); k += 2) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if (i + k - 1 < n && j + k - 1 < m) {
          F[(k + 1) / 2][i][j] =
              F[(k + 1) / 2 - 2][i + 2][j + 2] + suma(i, j, k);
          ans = max(ans, F[(k + 1) / 2][i][j]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
