#include <bits/stdc++.h>
using namespace std;
inline long long ceil(long long a, long long b) { return (a + b - 1) / b; }
const long long N = 505;
long long sm[N][N], dp[N][N];
inline long long calc(long long i, long long j, long long l) {
  long long ans = sm[i + l - 1][j + l - 1] -
                  (sm[i - 1][j + l - 1] + sm[i + l - 1][j - 1]) +
                  sm[i - 1][j - 1];
  return ans;
}
void func() {
  long long n, m;
  cin >> n >> m;
  long long arr[n + 1][m + 1];
  for (long long i = 1; i < n + 1; i++)
    for (long long j = 1; j < m + 1; j++) cin >> arr[i][j];
  for (long long i = 0; i < n + 1; i++) sm[i][0] = 0;
  for (long long j = 0; j < m + 1; j++) sm[0][j] = 0;
  for (long long i = 1; i < n + 1; i++) {
    long long temp = 0;
    for (long long j = 1; j < m + 1; j++) {
      temp += arr[i][j];
      sm[i][j] = sm[i - 1][j] + temp;
    }
  }
  long long mx = -LONG_LONG_MAX;
  for (long long i = 1; i < n - 1; i++) {
    for (long long j = 1; j < m - 1; j++) {
      long long x = calc(i, j, 3);
      x -= (arr[i + 1][j] + arr[i + 1][j + 1]);
      dp[i][j] = x;
      mx = max(mx, dp[i][j]);
    }
  }
  for (long long l = 5; l <= min(n, m); l += 2) {
    for (long long i = 1; i < n + 1; i++) {
      for (long long j = 1; j < m + 1; j++) {
        if (l > min(m - j + 1, n - i + 1)) continue;
        dp[i][j] = calc(i, j, l);
        dp[i][j] -= arr[i + 1][j];
        dp[i][j] -= dp[i + 1][j + 1];
        mx = max(mx, dp[i][j]);
      }
    }
  }
  cout << mx << "\n";
}
int main() {
  {
    ios ::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  }
  long long ntc = 1;
  for (long long i = 1; i < ntc + 1; i++) {
    func();
  }
  return 0;
}
