#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
struct Field {
  int t1[512][512];
  int t2[512][512];
};
Field f[2];
Field *f1, *f2;
int a[512][512];
int b[512][512];
int sq(int i1, int j1, int i2, int j2) {
  return b[i2][j2] - b[i2][j1] - b[i1][j2] + b[i1][j1];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      b[i][j] = a[i - 1][j - 1] + b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1];
  f1 = &f[0];
  f2 = &f[1];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) f1->t1[i][j] = f1->t2[i][j] = a[i][j];
  int minnm = min(n, m);
  int ans = -inf;
  for (int q = 3; q <= minnm; q += 2) {
    for (int i = 0; i + q <= n; ++i)
      for (int j = 0; j + q <= m; ++j) {
        f2->t1[i][j] = f1->t2[i + 2][j] + sq(i, j, i + 1, j + q) +
                       sq(i + 1, j + q - 1, i + q, j + q) +
                       a[i + q - 1][j + q - 2];
        f2->t2[i][j] = f1->t1[i][j + 2] + sq(i + q - 1, j, i + q, j + q) +
                       sq(i, j, i + q - 1, j + 1) + a[i][j + 1];
        ans = max(ans, f2->t1[i][j]);
      }
    swap(f1, f2);
  }
  cout << ans << '\n';
  return 0;
}
