#include <bits/stdc++.h>
using namespace std;
const int N = 510;
int n, m, ans = -1e9;
int a[N][N], s[N][N];
int dp[3][N][N];
inline bool valid(int i, int j, int k) {
  return i + k - 1 <= n && j + k - 1 <= m;
}
inline int sum(int x1, int y1, int x2, int y2) {
  return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      dp[0][i][j] = a[i][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++) {
      if (valid(i, j, 3)) {
        dp[1][i][j] = sum(i, j, i + 2, j + 2) - a[i + 1][j] - a[i + 1][j + 1];
        ans = max(ans, dp[1][i][j]);
      }
    }
  }
  for (int k = 5; k <= m && k <= n; k += 2) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (valid(i, j, k)) {
          dp[2][i][j] = sum(i, j, i + k - 1, j + k - 1) -
                        sum(i + 1, j + 1, i + k - 2, j + k - 2) - a[i + 1][j] +
                        a[i + 2][j + 1] + dp[0][i + 2][j + 2];
          ans = max(ans, dp[2][i][j]);
        }
      }
    }
    swap(dp[0], dp[1]);
    swap(dp[1], dp[2]);
  }
  printf("%d", ans);
  return 0;
}
