#include <bits/stdc++.h>
int const maxsize = 501;
int s[maxsize][maxsize] = {};
int dp[255][maxsize][maxsize] = {};
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> nums(n, std::vector<int>(m));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int a;
      std::cin >> a;
      nums[i][j] = a;
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      s[i][j] =
          s[i - 1][j] + s[i][j - 1] + nums[i - 1][j - 1] - s[i - 1][j - 1];
    }
  }
  int max = -1000000000;
  int km = std::min(n, m);
  for (int k = 3; k <= km; k += 2) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        if ((i + k) <= n && (j + k) <= m) {
          int sum = s[i + k][j + k] - s[i + k][j] - s[i][j + k] + s[i][j];
          sum -= s[i + 1][j + 1] - s[i + k - 1][j + 1] - s[i + 1][j + k - 1] +
                 s[i + k - 1][j + k - 1];
          sum -= nums[i + 1][j];
          if (k == 5) {
            sum += nums[i + 2][j + 1];
            sum += nums[i + 2][j + 2];
          } else if (k > 5) {
            sum += nums[i + 2][j + 1];
            sum += dp[(k - 4 - 1) / 2][i + 2][j + 2];
          }
          dp[(k - 1) / 2][i][j] = sum;
          max = std::max(max, sum);
        }
      }
    }
  }
  std::cout << max << std::endl;
}
