#include <bits/stdc++.h>
using namespace std;
const int MAXN = 555;
int R, C, grid[MAXN][MAXN], sums[MAXN][MAXN], answer = -1023456789;
inline int get(int r1, int c1, int r2, int c2) {
  return sums[r2][c2] - sums[r1 - 1][c2] - sums[r2][c1 - 1] +
         sums[r1 - 1][c1 - 1];
}
inline bool okay(int r, int c, int k) {
  return r - k / 2 > 0 && r + k / 2 <= R && c - k / 2 > 0 && c + k / 2 <= C;
}
inline int work(int cur, int r, int c, int k) {
  cur += get(r - k / 2, c - k / 2, r + k / 2, c + k / 2);
  cur -= get(r - k / 2 + 1, c - k / 2 + 1, r + k / 2 - 1, c + k / 2 - 1);
  cur -= grid[r - k / 2 + 1][c - k / 2];
  if (k > 3) cur += grid[r - k / 2 + 2][c - k / 2 + 1];
  return cur;
}
int main() {
  scanf("%d %d", &R, &C);
  for (int i = 1; i <= R; i++)
    for (int j = 1; j <= C; j++) {
      scanf("%d", &grid[i][j]);
      sums[i][j] =
          sums[i - 1][j] + sums[i][j - 1] - sums[i - 1][j - 1] + grid[i][j];
    }
  for (int i = 1; i <= R; i++)
    for (int j = 1; j <= C; j++) {
      int cur = grid[i][j];
      for (int k = 5; okay(i, j, k); k += 4) {
        cur = work(cur, i, j, k);
        answer = max(cur, answer);
      }
      cur = 0;
      for (int k = 3; okay(i, j, k); k += 4) {
        cur = work(cur, i, j, k);
        answer = max(cur, answer);
      }
    }
  printf("%d\n", answer);
  return 0;
}
