#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > table, prefix;
vector<vector<vector<int> > > d;
int n, m, p;
int sum(int a, int b, int c, int d) {
  return prefix[c][d] - (a == 0
                             ? (b == 0 ? 0 : prefix[c][b - 1])
                             : (b == 0 ? prefix[a - 1][d]
                                       : prefix[c][b - 1] + prefix[a - 1][d] -
                                             prefix[a - 1][b - 1]));
}
int dynamic() {
  int i, j, k, res = -1000000000;
  d[0] = table;
  for (k = 3; k < p; k += 2) {
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (i + k - 1 < n && j + k - 1 < m)
          d[1][i][j] = sum(i, j, i + k - 1, j + k - 1) - d[0][i + 1][j + 1] -
                       table[i + 1][j],
          res = max(res, d[1][i][j]);
      }
    }
    d[0] = d[1];
    d[1].assign(n, vector<int>(m, 0));
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  int i, j;
  cin >> n >> m;
  p = 502;
  table.resize(n, vector<int>(m));
  prefix.resize(n, vector<int>(m));
  d.resize(2, vector<vector<int> >(n, vector<int>(m)));
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> table[i][j];
      prefix[i][j] = table[i][j] +
                     (i == 0 ? (j == 0 ? 0 : prefix[i][j - 1])
                             : (j == 0 ? prefix[i - 1][j]
                                       : prefix[i - 1][j] + prefix[i][j - 1] -
                                             prefix[i - 1][j - 1]));
    }
  }
  cout << dynamic() << endl;
  return 0;
}
