#include <bits/stdc++.h>
int table[501][501][250];
int preSumRow[501][501];
int preSumCol[501][501];
int in[501][501];
inline void preprocess(int x, int y) {
  for (int i = 1; i <= x; ++i) {
    int sum = 0;
    for (int j = 1; j <= y; ++j) {
      sum += in[i][j];
      preSumRow[i][j] = sum;
    }
  }
  for (int j = 1; j <= y; ++j) {
    int sum = 0;
    for (int i = 1; i <= x; ++i) {
      sum += in[i][j];
      preSumCol[i][j] = sum;
    }
  }
}
inline int row_sum(int i, int j0, int j1) {
  return preSumRow[i][j1] - preSumRow[i][j0 - 1];
}
inline int col_sum(int i0, int i1, int j) {
  return preSumCol[i1][j] - preSumCol[i0 - 1][j];
}
int main(int argc, char** argv) {
  int x, y;
  scanf("%d %d", &x, &y);
  for (int i = 1; i <= x; ++i) {
    for (int j = 1; j <= y; ++j) scanf("%d", &in[i][j]);
  }
  preprocess(x, y);
  int minAxis = x > y ? y : x;
  int maxEdge = minAxis - (minAxis + 1) % 2;
  int nEdge = maxEdge / 2 + 1;
  for (int i = 1; i <= x; ++i) {
    for (int j = 1; j <= y; ++j) {
      for (int l = 0; l < nEdge; ++l) {
        table[i][j][l] = -123456789;
      }
      table[i][j][0] = in[i][j];
    }
  }
  int maxSum = INT_MIN;
  for (int l = 3; l <= maxEdge; l += 2) {
    for (int j = 1; j <= y; ++j) {
      for (int i = 1; i <= x; ++i) {
        if (i + l > x + 1 || j + l > y + 1) continue;
        int sum = 0;
        if (l == 3) {
          sum = row_sum(i, j, j + 2) + in[i + 1][j + 2] +
                row_sum(i + 2, j, j + 2);
          table[i][j][l / 2] = sum;
        }
        if (l >= 5) {
          int a = row_sum(i, j, j + l - 1) +
                  col_sum(i + 1, i + l - 2, j + l - 1) +
                  row_sum(i + l - 1, j, j + l - 1) +
                  col_sum(i + 2, i + l - 2, j) + in[i + 2][j + 1];
          sum = a + table[i + 2][j + 2][(l - 4) / 2];
          table[i][j][l / 2] = sum;
        }
        if (maxSum < sum) maxSum = sum;
      }
    }
  }
  printf("%d\n", maxSum);
  return 0;
}
