#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, dp[N][N], a[N][N];
inline int get(int x1, int y1, int x2, int y2) {
  return dp[x2][y2] - dp[x2][y1 - 1] - dp[x1 - 1][y2] + dp[x1 - 1][y1 - 1];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + a[i][j];
    }
  }
  int ans = -2e9;
  for (int i = 2; i < n; i++) {
    for (int j = 2; j < m; j++) {
      int cur = get(i - 1, j - 1, i + 1, j + 1) - a[i][j] - a[i][j - 1];
      ans = max(ans, cur);
      int x1 = i - 2, y1 = j - 2, x2 = i + 2, y2 = j + 2;
      while (x1 >= 1 && y1 >= 1 && x2 <= n && y2 <= m) {
        cur = get(x1, y1, x2, y2) - cur - a[x1 + 1][y1];
        ans = max(ans, cur);
        x1--;
        y1--;
        x2++;
        y2++;
      }
    }
  }
  cout << ans;
}
