#include <bits/stdc++.h>
using namespace std;
bitset<251> done[501][501];
int M[501][501], S[501][501], dp[501][501][251];
int f(int i, int j, int k) {
  if (done[i][j][k / 2]) return dp[i][j][k / 2];
  int ans, sum = S[i][j] - S[i + k][j] - S[i][j + k] + S[i + k][j + k];
  if (k == 3)
    ans = sum - M[i + 1][j] - M[i + 1][j + 1];
  else
    ans = sum - f(i + 1, j + 1, k - 2) - M[i + 1][j];
  done[i][j][k / 2] = 1;
  dp[i][j][k / 2] = ans;
  return ans;
}
int main() {
  int R, C;
  while (cin >> R >> C) {
    for (int i = 0; i < R; i++)
      for (int j = 0; j < C; j++) cin >> M[i][j];
    memset(S, 0, sizeof(S));
    for (int i = R - 1; i >= 0; i--)
      for (int j = C - 1; j >= 0; j--)
        S[i][j] = M[i][j] + S[i + 1][j] + S[i][j + 1] - S[i + 1][j + 1];
    int ans = -1 << 30;
    for (int i = 0; i < 501; i++)
      for (int j = 0; j < 501; j++) done[i][j].reset();
    for (int i = 0; i < R; i++)
      for (int j = 0; j < C; j++)
        for (int k = 3; i + k <= R && j + k <= C; k += 2)
          ans = max(ans, f(i, j, k));
    cout << ans << endl;
  }
  return 0;
}
