#include <bits/stdc++.h>
using namespace std;
int T[1000][1000];
int ro[1000][1000];
int co[1000][1000];
int getRow(int row, int c1, int c2) { return ro[row][c2 + 1] - ro[row][c1]; }
int getCol(int col, int r1, int r2) { return co[r2 + 1][col] - co[r1][col]; }
char buf[100000];
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (M); ++j) scanf("%d", &T[i][j]);
  for (int i = 0; i < (N); ++i) {
    int su = 0;
    for (int j = 0; j < (M + 1); ++j) {
      ro[i][j] = su;
      su += T[i][j];
    }
  }
  for (int j = 0; j < (M); ++j) {
    int su = 0;
    for (int i = 0; i < (N + 1); ++i) {
      co[i][j] = su;
      su += T[i][j];
    }
  }
  int result = -1000000000;
  for (int i = (2); i < (N); ++i)
    for (int j = 0; j < (M - 2); ++j) {
      int temp = getRow(i, j, j + 1) + getCol(j + 2, i - 2, i) +
                 getRow(i - 2, j, j + 1);
      result = max(result, temp);
      int left = j, right = j + 2, top = i - 2, bottom = i;
      while (true) {
        left -= 2, right += 2, top -= 2, bottom += 2;
        if (left < 0 || right >= M || top < 0 || bottom >= N) break;
        temp += getRow(top + 2, left, left + 1) +
                getCol(left, top + 3, bottom) +
                getRow(bottom, left + 1, right) +
                getCol(right, top, bottom - 1) + getRow(top, left, right - 1);
        result = max(result, temp);
      }
    }
  for (int i = 0; i < (N); ++i)
    for (int j = 0; j < (M); ++j) {
      int temp = T[i][j];
      int left = j, right = j, top = i, bottom = i;
      while (true) {
        left -= 2, right += 2, top -= 2, bottom += 2;
        if (left < 0 || right >= M || top < 0 || bottom >= N) break;
        temp += getRow(top + 2, left, left + 1) +
                getCol(left, top + 3, bottom) +
                getRow(bottom, left + 1, right) +
                getCol(right, top, bottom - 1) + getRow(top, left, right - 1);
        result = max(result, temp);
      }
    }
  printf("%d\n", result);
}
