#include <bits/stdc++.h>
using namespace std;
const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};
long long a[512][512];
int b[512][512];
int main(void) {
  for (int ks = 1, n, m; 2 == scanf("%d %d", &n, &m); ++ks) {
    memset(a, 0, sizeof(a));
    for (int i = 1, x; i <= n; ++i) {
      for (int j = 1; j <= m && 1 == scanf("%d", &x); ++j)
        a[i][j] = a[i][j - 1] + x, b[i][j] = x;
      for (int j = 1; j <= m; ++j) a[i][j] += a[i - 1][j];
    }
    long long t = -10000000000000000LL;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        long long v = b[i][j];
        for (int k = 1; i - k > 0 && i + k <= n && j - k > 0 && j + k <= m;
             ++k) {
          v = a[i + k][j + k] - a[i - k - 1][j + k] - a[i + k][j - k - 1] +
              a[i - k - 1][j - k - 1] - v - b[i - k + 1][j - k];
          t = max(t, v);
        }
      }
    cout << t << endl;
  }
  return 0;
}
