#include <bits/stdc++.h>
int INF = 2000000000;
using namespace std;
int maxer = -INF;
int a[501][501];
int dp[501][501][5];
int n, m;
int rowsum[501][501];
int colsum[501][501];
void find(int x, int y, int k) {
  int xx, yy;
  xx = x;
  yy = y;
  if (k == 1) {
    dp[xx][yy][k] = a[x][y];
    return;
  }
  if (k == 3) {
    dp[xx][yy][k] = a[x][y] + a[x][y + 1] + a[x][y + 2] + a[x + 1][y + 2] +
                    a[x + 2][y + 2] + a[x + 2][y + 1] + a[x + 2][y];
    maxer = max(dp[xx][yy][k], maxer);
    return;
  }
  dp[xx][yy][k % 5] = 0;
  dp[xx][yy][k % 5] += (rowsum[x][y + k - 1] - rowsum[x][y] + a[x][y]);
  x++;
  y = y + k - 1;
  dp[xx][yy][k % 5] += (colsum[x + k - 2][y] - colsum[x][y] + a[x][y]);
  x = x + k - 2;
  y--;
  dp[xx][yy][k % 5] += (rowsum[x][y] - rowsum[x][y - k + 2] + a[x][y - k + 2]);
  x--;
  y = y - (k - 2);
  dp[xx][yy][k % 5] += (colsum[x][y] - colsum[x - k + 4][y] + a[x - k + 4][y]);
  x -= (k - 4);
  y++;
  dp[xx][yy][k % 5] += a[x][y];
  y++;
  dp[xx][yy][k % 5] += dp[x][y][(k - 4) % 5];
  maxer = max(dp[xx][yy][k % 5], maxer);
}
int main() {
  int i, j;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> a[i][j];
      if (j == 0)
        rowsum[i][j] = a[i][j];
      else
        rowsum[i][j] = rowsum[i][j - 1] + a[i][j];
    }
  }
  for (j = 0; j < m; j++)
    for (int i = 0; i < n; i++) {
      if (i == 0)
        colsum[i][j] = a[i][j];
      else
        colsum[i][j] = colsum[i - 1][j] + a[i][j];
    }
  for (int k = 1; k <= min(n, m); k += 2) {
    for (int i = 0; i <= n - k; i++)
      for (int j = 0; j <= m - k; j++) {
        find(i, j, k);
      }
  }
  cout << maxer;
  return 0;
}
