#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > mas, HO, VE;
int n, m;
long long sumHO(int j, int a, int b) {
  long long res = HO[j][b];
  if (a) res -= HO[j][a - 1];
  return res;
}
long long sumVE(int i, int a, int b) {
  long long res = VE[b][i];
  if (a) res -= VE[a - 1][i];
  return res;
}
bool valid(int j, int i) { return j >= 0 && i >= 0 && j < n && i < m; }
int main() {
  scanf("%d %d", &n, &m);
  mas.resize(n, vector<long long>(m));
  HO.resize(n, vector<long long>(m));
  VE.resize(n, vector<long long>(m));
  for (int j = (0); j < (n); ++j)
    for (int i = (0); i < (m); ++i) cin >> mas[j][i];
  for (int j = (0); j < (n); ++j) {
    HO[j][0] = mas[j][0];
    for (int i = (1); i < (m); ++i) HO[j][i] = mas[j][i] + HO[j][i - 1];
  }
  for (int i = (0); i < (m); ++i) {
    VE[0][i] = mas[0][i];
    for (int j = (1); j < (n); ++j) VE[j][i] = mas[j][i] + VE[j - 1][i];
  }
  long long best = -(1LL << 60);
  for (int J = (0); J < (n); ++J)
    for (int I = (0); I < (m); ++I) {
      if (valid(J + 2, I + 2)) {
        int add = 2;
        long long res = sumHO(J, I, I + 2) + sumHO(J + 2, I, I + 2) +
                        sumVE(I + 2, J + 1, J + 1);
        best = ((best >= res) ? best : res);
        for (int k = 7; k < 512; k += 4, add += 2) {
          int y = J - add, x = I - add;
          if (!valid(y + k - 1, x + k - 1) || !valid(y, x)) break;
          res += mas[y + 2][x + 1] - mas[y + 1][x] + sumHO(y, x, x + k - 1) +
                 sumHO(y + k - 1, x, x + k - 1) + sumVE(x, y + 1, y + k - 2) +
                 sumVE(x + k - 1, y + 1, y + k - 2);
          best = ((best >= res) ? best : res);
        }
      }
      if (valid(J + 4, I + 4)) {
        int add = 2;
        long long res =
            mas[J + 2][I + 1] + mas[J + 2][I + 2] + sumHO(J, I, I + 5 - 1) +
            sumHO(J + 5 - 1, I, I + 5 - 1) + sumVE(I, J + 2, J + 5 - 2) +
            sumVE(I + 5 - 1, J + 1, J + 5 - 2);
        best = ((best >= res) ? best : res);
        for (int k = 9; k < 512; k += 4, add += 2) {
          int y = J - add, x = I - add;
          if (!valid(y + k - 1, x + k - 1) || !valid(y, x)) break;
          res += mas[y + 2][x + 1] - mas[y + 1][x] + sumHO(y, x, x + k - 1) +
                 sumHO(y + k - 1, x, x + k - 1) + sumVE(x, y + 1, y + k - 2) +
                 sumVE(x + k - 1, y + 1, y + k - 2);
          best = ((best >= res) ? best : res);
        }
      }
    }
  cout << best << endl;
  return 0;
}
