#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int mod = 31;
void solve();
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
char res[505][505][505];
int otvet = -INF;
vector<vector<int> > a;
vector<vector<int> > versum, gorsum;
int win(int i, int j, int kol) {
  if (kol == 3) {
    int cur = versum[i][j + 2] - versum[i][j - 1] + versum[i + 2][j + 2] -
              versum[i + 2][j - 1] + a[i + 1][j + 2];
    if (otvet < cur) otvet = cur;
    return cur;
  }
  if (kol == 1) {
    int cur = a[i][j];
    return a[i][j];
  }
  int cur = win(i + 2, j + 2, kol - 4);
  cur += versum[i][j + kol - 1] - versum[i][j - 1];
  cur += versum[i + kol - 1][j + kol - 1] - versum[i + kol - 1][j - 1];
  cur += gorsum[j][i + kol - 2] - gorsum[j][i + 1];
  cur += gorsum[j + kol - 1][i + kol - 2] - gorsum[j + kol - 1][i];
  cur += a[i + 2][j + 1];
  if (otvet < cur) otvet = cur;
  res[i][j][kol] = 1;
  return cur;
}
void solve() {
  int n, m;
  cin >> n >> m;
  n++, m++;
  memset(res, 0, sizeof res);
  a.resize(n);
  for (int i = 1; i < n; i++) {
    a[i].resize(m);
    for (int q = 1; q < m; q++) scanf("%d", &a[i][q]);
  }
  versum.resize(n);
  for (int i = 1; i < n; i++) {
    versum[i].resize(m);
    versum[i][0] = 0;
    for (int q = 1; q < m; q++) {
      int pref = versum[i][q - 1];
      versum[i][q] = pref + a[i][q];
    }
  }
  gorsum.resize(m);
  for (int i = 1; i < m; i++) {
    gorsum[i].resize(n);
    gorsum[i][0] = 0;
    for (int q = 1; q < n; q++) {
      int pref = gorsum[i][q - 1];
      gorsum[i][q] = pref + a[q][i];
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j < m; j++) {
      for (int kol = 3; kol < n; kol += 2) {
        if (res[i][j][kol] == 0 && i + kol <= n && j + kol <= m) {
          res[i][j][kol] = 1;
          win(i, j, kol);
        }
      }
    }
  }
  printf("%d", otvet);
  return;
}
