#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int n, m;
int src[510][510];
int sum[510][510];
int res;
void dospiral(vector<pair<int, int> > &sp, int a, int b) {
  int s = src[a][b];
  for (int i = 0; i < ((int)(sp).size()); ++i) {
    int aa = a + sp[i].first;
    int bb = b + sp[i].second;
    if (aa < 0 || aa >= n || bb < 0 || bb >= m) break;
    s += sum[max(a, aa) + 1][max(b, bb) + 1] - sum[min(a, aa)][max(b, bb) + 1] -
         sum[max(a, aa) + 1][min(b, bb)] + sum[min(a, aa)][min(b, bb)] -
         src[a][b];
    a = aa;
    b = bb;
    if ((i + 1) % 5 == 0) res = max(res, s);
  }
}
int main() {
  vector<pair<int, int> > sp1, sp2;
  sp1.push_back(make_pair(0, 2));
  sp1.push_back(make_pair(-2, 0));
  sp1.push_back(make_pair(0, -2));
  sp1.push_back(make_pair(0, 0));
  sp1.push_back(make_pair(0, 0));
  for (int l = 6; l <= 600; l += 4) {
    sp1.push_back(make_pair(0, -2));
    sp1.push_back(make_pair(l - 2, 0));
    sp1.push_back(make_pair(0, l));
    sp1.push_back(make_pair(-l, 0));
    sp1.push_back(make_pair(0, -l));
    sp2.push_back(make_pair(0, -2));
    sp2.push_back(make_pair(l - 4, 0));
    sp2.push_back(make_pair(0, l - 2));
    sp2.push_back(make_pair(-(l - 2), 0));
    sp2.push_back(make_pair(0, -(l - 2)));
  }
  cin >> n >> m;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      cin >> src[i][j];
      sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + src[i][j];
    }
  }
  res = -1000000000 * 2;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      dospiral(sp1, i, j);
      dospiral(sp2, i, j);
    }
  }
  cout << res;
  return 0;
}
