#include <bits/stdc++.h>
using namespace std;
int mat[501][501];
int acc[501][501];
int dp[501][501][250];
int n, m;
void process() {
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      acc[i][j] = mat[i][j] + acc[i][j - 1] + acc[i - 1][j] - acc[i - 1][j - 1];
}
int calc(int i1, int j1, int i2, int j2) {
  int res = 0;
  res += acc[i1][j1];
  res -= acc[i1][j2 - 1];
  res -= acc[i2 - 1][j1];
  res += acc[i2 - 1][j2 - 1];
  return res;
}
int solve(int i, int j, int k) {
  if (k == 1) return mat[i][j];
  if (dp[i][j][k / 2] != -1) return dp[i][j][k / 2];
  int tk = k, ti = i, tj = j;
  --k;
  int res = calc(i, j + k, i, j);
  j += k;
  res += calc(i + k, j, i + 1, j);
  i += k;
  res += calc(i, j - 1, i, j - k);
  j -= k;
  k -= 2;
  if (k >= 2) {
    res += calc(i - 1, j, i - k, j);
    i -= k;
    res += mat[i][j + 1];
    res += solve(i, j + 2, k - 1);
  }
  return dp[ti][tj][tk / 2] = res;
}
int main() {
  scanf("%d%d", &n, &m);
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &mat[i][j]);
  process();
  int res = -1000000000;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      for (int k = 3; k <= 501; k += 2) {
        if (i + k - 1 > n || j + k - 1 > m) break;
        res = max(res, solve(i, j, k));
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
