#include <bits/stdc++.h>
using namespace std;
int n, m, ans, g, K;
int number[510][510], sum[2][510][510], num[510][510];
bool flag;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &number[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) sum[1][i][j] = number[i][j];
  for (int j = 1; j <= m; j++) num[1][j] = num[1][j - 1] + number[1][j];
  for (int i = 2; i <= n; i++) {
    num[i][1] = num[i - 1][1] + number[i][1];
    for (int j = 2; j <= m; j++)
      num[i][j] =
          num[i - 1][j] + num[i][j - 1] + number[i][j] - num[i - 1][j - 1];
  }
  K = min(n, m);
  g = 1;
  for (int k = 3; k <= K; k += 2, g = 1 - g)
    for (int i = k; i <= n; i++)
      for (int j = k; j <= m; j++) {
        sum[1 - g][i][j] = num[i][j] - num[i - k][j] - num[i][j - k] +
                           num[i - k][j - k] - sum[g][i - 1][j - 1] -
                           number[i - k + 2][j - k + 1];
        if (flag)
          ans = max(ans, sum[1 - g][i][j]);
        else
          ans = sum[1 - g][i][j];
        flag = 1;
      }
  printf("%d\n", ans);
  return 0;
}
