#include <bits/stdc++.h>
using namespace std;
long long rec[600][600];
long long crec[600][600];
long long rrec[600][600];
long long tmp1, tmp2;
long long M;
int n, m, p;
void cal(int i, int j) {
  tmp1 = tmp2 = 0;
  for (int k = 1; i + k <= n && i - k >= 1 && j + k <= m && j - k >= 1;
       k += 2) {
    if (k == 1) {
      tmp1 = rrec[i - 1][j + 1] - rrec[i - 1][j - 2] + rrec[i + 1][j + 1] -
             rrec[i + 1][j - 2] + rec[i][j + 1];
    } else {
      tmp1 += rrec[i - k][j + k] - rrec[i - k][j - k - 1] + crec[i + k][j + k] -
              crec[i - k][j + k] + rrec[i + k][j + k - 1] -
              rrec[i + k][j - k - 1] + crec[i + k - 1][j - k] -
              crec[i - k + 1][j - k] + rec[i - k + 2][j - k + 1];
    }
    M = max(M, tmp1);
  }
  for (int k = 2; i + k <= n && i - k >= 1 && j + k <= m && j - k >= 1;
       k += 2) {
    if (k == 2) {
      tmp2 = rrec[i - k][j + k] - rrec[i - k][j - k - 1] + crec[i + k][j + k] -
             crec[i - k][j + k] + rrec[i + k][j + k - 1] -
             rrec[i + k][j - k - 1] + crec[i + k - 1][j - k] -
             crec[i - k + 1][j - k] + rec[i - k + 2][j - k + 1] + rec[i][j];
    } else {
      tmp2 += rrec[i - k][j + k] - rrec[i - k][j - k - 1] + crec[i + k][j + k] -
              crec[i - k][j + k] + rrec[i + k][j + k - 1] -
              rrec[i + k][j - k - 1] + crec[i + k - 1][j - k] -
              crec[i - k + 1][j - k] + rec[i - k + 2][j - k + 1];
    }
    M = max(M, tmp2);
  }
  return;
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    memset(rec, 0, sizeof(rec));
    memset(crec, 0, sizeof(crec));
    memset(rrec, 0, sizeof(rrec));
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) scanf("%I64d", &rec[i][j]);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) rrec[i][j] = rrec[i][j - 1] + rec[i][j];
    for (int j = 1; j <= m; j++)
      for (int i = 1; i <= n; i++) crec[i][j] = crec[i - 1][j] + rec[i][j];
    M = -7001;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        cal(i, j);
      }
    printf("%I64d\n", M);
  }
  return 0;
}
