#include <bits/stdc++.h>
using namespace std;
int r[500][500], c[500][500], f[500][500], dp[3][500][500];
int main() {
  int n, m, i, j, k;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> k;
      f[i][j] = k;
      r[i][j] = j == 0 ? k : r[i][j - 1] + k;
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < n; j++) {
      c[i][j] = j == 0 ? f[j][i] : c[i][j - 1] + f[j][i];
    }
  }
  int Max = -1000000000;
  int pre, cur, id = 0;
  for (i = 1; i < 500; i += 2, id++) {
    cur = id % 3, pre = (id + 1) % 3;
    for (j = 0; j + i <= n; j++) {
      for (k = 0; k + i <= m; k++) {
        if (i == 1)
          dp[cur][j][k] = f[j][k];
        else if (i == 3) {
          dp[cur][j][k] = r[j][k + i - 1] - (k > 0 ? r[j][k - 1] : 0) +
                          c[k + i - 1][j + i - 1] - c[k + i - 1][j] +
                          r[j + i - 1][k + i - 2] -
                          (k > 0 ? r[j + i - 1][k - 1] : 0);
        } else {
          dp[cur][j][k] = dp[pre][j + 2][k + 2] + r[j][k + i - 1] -
                          (k > 0 ? r[j][k - 1] : 0) + c[k + i - 1][j + i - 1] -
                          c[k + i - 1][j] + r[j + i - 1][k + i - 2] -
                          (k > 0 ? r[j + i - 1][k - 1] : 0) + c[k][j + i - 2] -
                          c[k][j + 1] + f[j + 2][k + 1];
        }
        if (i > 1) Max = max(Max, dp[cur][j][k]);
      }
    }
  }
  cout << Max << endl;
}
