#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:56777216")
int n, m;
int a[510][510];
int sum[510][510];
int useSum[510][500];
int Sum(int i, int j) {
  if (i < 0 || j < 0) return 0;
  if (useSum[i][j]) return sum[i][j];
  useSum[i][j] = true;
  int& r = sum[i][j];
  r = Sum(i - 1, j) + Sum(i, j - 1) - Sum(i - 1, j - 1) + a[i][j];
  return r;
}
int Sum(int i1, int j1, int i2, int j2) {
  return Sum(i2, j2) - Sum(i1 - 1, j2) - Sum(i2, j1 - 1) + Sum(i1 - 1, j1 - 1);
}
int dp[500][500][2];
bool use[500][500][2];
int Dp(int i, int j, int k, int len) {
  if (use[i][j][k]) {
    return dp[i][j][k];
  }
  use[i][j][k] = true;
  int& r = dp[i][j][k] = 0;
  if (len == 3) {
    r = 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];
    return r;
  }
  int inner = Dp(i + 1, j + 1, 1 - k, len - 2);
  int s = Sum(i, j, i + len - 1, j + len - 1);
  r = s - inner - a[i + 1][j];
  return r;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  int ans = -1000000000;
  int cur = 0;
  int k = 3;
  for (; k <= n && k <= m; k += 2) {
    for (int i = 0; i < 500; i++) {
      for (int j = 0; j < 500; j++) {
        use[i][j][1 - cur] = false;
      }
    }
    for (int i = 0; i <= n - k; i++) {
      for (int j = 0; j <= m - k; j++) {
        ans = max(ans, Dp(i, j, 1 - cur, k));
      }
    }
    cur = 1 - cur;
  }
  printf("%d\n", ans);
  return 0;
}
