#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const long long LLINF = 1000000000000000007LL;
const double EPS = 1e-9;
const int sz = 200100;
int ar[600][600];
int p[600][600];
int suf_sum_2d(int i1, int j1, int i2, int j2) {
  return p[i2 + 1][j2 + 1] - p[i2 + 1][j1] - p[i1][j2 + 1] + p[i1][j1];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> ar[i][j];
      p[i + 1][j + 1] = p[i][j + 1] + p[i + 1][j] - p[i][j] + ar[i][j];
    }
  }
  int mx = -INF;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int r = min(min(i + 1, j + 1), min(n - i, m - j));
      int res = ar[i][j];
      for (int k = 1; k < r; ++k) {
        res =
            suf_sum_2d(i - k, j - k, i + k, j + k) - res - ar[i - k + 1][j - k];
        mx = max(mx, res);
      }
    }
  }
  cout << mx;
}
