#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10;
long long a[N][N], sum[N][N], n, m, oo = 1e9;
long long query(int x1, int y1, int x2, int y2) {
  long long ans =
      sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
  return 1ll * ans;
}
void build() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
  }
}
int main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      scanf("%lld", &a[i][j]);
    }
  }
  build();
  long long ans = -oo;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      long long cur = a[i][j];
      long long lim = min(min(i - 1, n - i), min(j - 1, m - j));
      for (long long d = 1; d <= lim; d++) {
        cur = query(i - d, j - d, i + d, j + d) - cur - a[i - d + 1][j - d];
        ans = max(ans, cur);
      }
    }
  }
  printf("%lld\n", ans);
}
