#include <bits/stdc++.h>
long long sum[510][510];
long long c[510][510];
long long a[510][510];
long long ans = 0;
int n, m;
void init_sum() {
  int i, j;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++)
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
}
long long area(int i, int j, int k) {
  long long res;
  int a = i + k - 1, b = j + k - 1;
  res = sum[a][b] - sum[a][j - 1] - sum[i - 1][b] + sum[i - 1][j - 1];
  return res;
}
void solv() {
  int i, j, k, t, t2;
  t = (n) < (m) ? (n) : (m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) c[i][j] = a[i][j];
  for (k = 3; k <= t; k += 2) {
    for (i = 1; i + k - 1 <= n; i++)
      for (j = 1; j + k - 1 <= m; j++) {
        t2 = area(i, j, k);
        c[i][j] = t2 - c[i + 1][j + 1] - a[i + 1][j];
        ans = (ans) > (c[i][j]) ? (ans) : (c[i][j]);
      }
  }
  printf("%I64d\n", ans);
}
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) scanf("%I64d", &a[i][j]);
  init_sum();
  ans = -1000 * 500 * 600;
  solv();
  return 0;
}
