#include <bits/stdc++.h>
using namespace std;
int ir, ic, grid[550][550], ps[550][550], sp[550][550];
void input() {
  scanf("%d%d", &ir, &ic);
  for (int r = 1; r <= ir; r++)
    for (int c = 1; c <= ic; c++) {
      scanf("%d", &grid[r][c]);
      sp[r][c] = grid[r][c];
    }
}
void preCompute() {
  for (int r = 1; r <= ir; r++) {
    for (int c = 1; c <= ic; c++) {
      ps[r][c] = grid[r][c] + ps[r - 1][c] + ps[r][c - 1] - ps[r - 1][c - 1];
    }
  }
}
int sum(int r1, int c1, int r2, int c2) {
  return ps[r2][c2] - ps[r1 - 1][c2] - ps[r2][c1 - 1] + ps[r1 - 1][c1 - 1];
}
int Sp(int r, int c, int s) {
  return sp[r][c] = sum(r, c, r + s - 1, c + s - 1) - sp[r + 1][c + 1] -
                    grid[r + 1][c];
}
int main() {
  input();
  preCompute();
  int highest = INT_MIN;
  for (int s = 3; s <= min(ir, ic); s += 2) {
    for (int r = 1; r + s - 1 <= ir; r++) {
      for (int c = 1; c + s - 1 <= ic; c++) {
        highest = max(Sp(r, c, s), highest);
      }
    }
  }
  printf("%d\n", highest);
}
