#include <bits/stdc++.h>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}
using namespace std;
int tate[500][500];
int yoko[500][500];
int g[500][500];
int main() {
  int h = getInt();
  int w = getInt();
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) g[i][j] = getInt();
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++) {
      if (j != 0) yoko[i][j] = yoko[i][j - 1];
      yoko[i][j] += g[i][j];
      if (i != 0) tate[i][j] = tate[i - 1][j];
      tate[i][j] += g[i][j];
    }
  long long ans = -10000000000ll;
  for (int y = 0; y < (int)(h - 2); y++)
    for (int x = 0; x < (int)(w - 2); x++) {
      long long ok = 0;
      long long bad = 0;
      for (int i = 0; i < (int)(3); i++)
        for (int j = 0; j < (int)(3); j++) {
          if (i == 1 && j == 0)
            bad += g[y + i][x + j];
          else if (i == 1 && j == 1)
            bad += g[y + i][x + j];
          else
            ok += g[y + i][x + j];
        }
      ans = max(ans, ok);
      int xx = x - 1;
      int yy = y - 1;
      for (int sz = 5; xx >= 0 && yy >= 0 && xx + sz <= w && yy + sz <= h;
           sz += 2) {
        swap(ok, bad);
        ok += yoko[yy][xx + sz - 1];
        if (xx > 0) ok -= yoko[yy][xx - 1];
        ok += yoko[yy + sz - 1][xx + sz - 1];
        if (xx > 0) ok -= yoko[yy + sz - 1][xx - 1];
        ok += tate[yy + sz - 1][xx];
        if (yy > 0) ok -= tate[yy - 1][xx];
        ok += tate[yy + sz - 1][xx + sz - 1];
        if (yy > 0) ok -= tate[yy - 1][xx + sz - 1];
        ok -= g[yy][xx];
        ok -= g[yy][xx + sz - 1];
        ok -= g[yy + sz - 1][xx];
        ok -= g[yy + sz - 1][xx + sz - 1];
        ok -= g[yy + 1][xx];
        bad += g[yy + 1][xx];
        ans = max(ans, ok);
        xx--;
        yy--;
      }
    }
  cout << ans << endl;
  return 0;
}
