#include <bits/stdc++.h>
using namespace std;
const int N = 510;
const int M = 250;
const int INF = 1e9;
int a[N][N], n, m, ans = -INF;
int dp[M][N][N], sum[N][N];
int getsum(int x1, int y1, int x2, int y2) {
  int s1 = sum[x2][y2];
  int s2 = (x1 > 0 ? sum[x1 - 1][y2] : 0);
  int s3 = (y1 > 0 ? sum[x2][y1 - 1] : 0);
  int s4 = (x1 > 0 && y1 > 0 ? sum[x1 - 1][y1 - 1] : 0);
  return s1 - s2 - s3 + s4;
}
int main() {
  cin >> n >> m;
  int x = min(n, m);
  x -= (x % 2 == 0);
  x = (x - 1) / 2 - 1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      int s1 = (i > 0 ? sum[i - 1][j] : 0);
      int s2 = (j > 0 ? sum[i][j - 1] : 0);
      int s3 = (i > 0 && j > 0 ? sum[i - 1][j - 1] : 0);
      sum[i][j] = a[i][j] + s1 + s2 - s3;
    }
  for (int i = 0; i + 2 < n; i++)
    for (int j = 0; j + 2 < m; j++) {
      dp[0][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];
      ans = max(ans, dp[0][i][j]);
    }
  for (int q = 1; q <= x; q++) {
    int len = (q + 1) * 2 + 1;
    for (int i = 0; i < n - len + 1; i++)
      for (int j = 0; j < m - len + 1; j++) {
        dp[q][i][j] = getsum(i, j, i + len - 1, j + len - 1) -
                      dp[q - 1][i + 1][j + 1] - a[i + 1][j];
        ans = max(ans, dp[q][i][j]);
      }
  }
  cout << ans;
  return 0;
}
