#include <bits/stdc++.h>
using namespace std;
int s[501][501], a[501][501], n, m, ans, sum;
int main() {
  ans = -2e9;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      cin >> a[i + 1][j + 1];
      s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + a[i + 1][j + 1];
    }
  for (int r = 2; r < n; r++)
    for (int c = 2; c < m; c++) {
      sum = a[r][c];
      int w = 1;
      while (r - w > 0 && r + w <= n && c - w > 0 && c + w <= m) {
        sum = s[r + w][c + w] - s[r + w][c - w - 1] - s[r - w - 1][c + w] +
              s[r - w - 1][c - w - 1] - sum - a[r - w + 1][c - w];
        ans = max(ans, sum);
        w++;
      }
    }
  cout << ans << endl;
}
