#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
unsigned long long MOD = int(1e9 + 7);
int X, Y;
int a[(int)(5e2 + 5)][(int)(5e2 + 5)], sum[(int)(5e2 + 5)][(int)(5e2 + 5)];
int squareVal(int x, int y, int d) {
  return sum[x][y] + sum[x + d][y + d] - sum[x + d][y] - sum[x][y + d];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> X >> Y;
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) cin >> a[i][j];
  }
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++)
      sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
  }
  int ans = -(1 << 30);
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      int mxd = min(min(i, X - i - 1), min(j, Y - j - 1));
      int tmp = a[i][j];
      for (int d = 1; d <= mxd; d++) {
        tmp = squareVal(i - d, j - d, 2 * d + 1) - tmp - a[i - d + 1][j - d];
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
