#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T getNext() {
  T s = 1, x = 0, c = getc(stdin);
  for (; c <= 32; c = getc(stdin))
    ;
  if (c == 45) s = -1, c = getc(stdin);
  for (; 48 <= c && c <= 57; x = x * 10 + c - 48, c = getc(stdin))
    ;
  return x * s;
}
const double eps = 1e-9;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)(2e5) + 256;
int a[555][555];
int d[501][501][250];
int x[501][501], y[501][501];
inline int getInRow(int i, int l, int r) { return y[i][r] - y[i][l - 1]; }
inline int getInCol(int j, int l, int r) { return x[r][j] - x[l - 1][j]; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      scanf("%d", &a[i][j]);
      x[i][j] += x[i - 1][j] + a[i][j];
      y[i][j] += y[i][j - 1] + a[i][j];
    }
  }
  for (int k = 0; k + k + 1 <= min(n, m); ++k) {
    for (int i = 1; i + k + k <= n; ++i) {
      for (int j = 1; j + k + k <= m; ++j) {
        int &res = d[i][j][k];
        if (!k) {
          res = a[i][j];
        } else {
          if (k == 1) {
            res = getInRow(i, j, j + 2) + getInRow(i + 2, j, j + 2) +
                  a[i + 1][j + 2];
          } else {
            res = getInRow(i, j, j + k + k) +
                  getInRow(i + k + k, j, j + k + k) +
                  getInCol(j + k + k, i + 1, i + k + k - 1) +
                  getInCol(j, i + 2, i + k + k - 1);
            res += a[i + 2][j + 1];
            res += d[i + 2][j + 2][k - 2];
          }
        }
      }
    }
  }
  int res = -INT_MAX;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      for (int k = 1; i + k + k <= n && j + k + k <= m; ++k) {
        res = max(res, d[i][j][k]);
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
