#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int sq[504][504], sum[504][504], dp[2][504][504];
int main() {
  int n, m;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i < n + 1; ++i)
    for (int j = 1; j < m + 1; ++j) cin >> sq[i][j];
  for (int i = 1; i < n + 1; ++i)
    for (int j = 1; j < m + 1; ++j)
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + sq[i][j];
  int mx = -1000000000;
  for (int i = 1; i < n + 1; ++i) {
    for (int j = 1; j < m + 1; ++j) {
      int n = i % 2, p = (i - 1) % 2,
          len = min(2 * ((i - 1) / 2) + 1, 2 * ((j - 1) / 2) + 1);
      dp[n][j][1] = sq[i][j];
      for (int k = 3; k <= len; k += 2) {
        dp[n][j][k] = sum[i][j] - sum[i - k][j] - sum[i][j - k] +
                      sum[i - k][j - k] - dp[p][j - 1][k - 2] -
                      sq[i - k + 2][j - k + 1];
        mx = max(dp[n][j][k], mx);
      }
    }
  }
  cout << mx << "\n";
  return 0;
}
