#include <bits/stdc++.h>
using namespace std;
template <typename T, size_t N>
struct array {
  T val[N];
  T& operator[](size_t n) {
    if (n >= N) assert(false);
    return val[n];
  }
  T* begin() { return &val[0]; }
  T* end() { return &val[0] + N; }
};
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
const int inf = 0x3f3f3f3f;
const long long inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-8;
const int maxn = 500;
short int field[maxn][maxn];
int rowsum[maxn][maxn];
int colsum[maxn][maxn];
int dp[maxn][maxn][maxn / 2];
inline int getRowSum(int row, int from, int to) {
  int res = rowsum[row][to];
  if (from != 0) res -= rowsum[row][from - 1];
  return res;
}
inline int getColSum(int col, int from, int to) {
  int res = colsum[col][to];
  if (from != 0) res -= colsum[col][from - 1];
  return res;
}
int n, m;
int solve(int row, int col, int k) {
  if (row + k > n || col + k > m) return inf;
  int& res = dp[row][col][k / 2];
  if (res != inf) return res;
  if (k == 3) {
    res = getRowSum(row, col, col + 2) + getRowSum(row + 2, col, col + 2) +
          field[row + 1][col + 2];
  } else if (k == 5) {
    res = getRowSum(row, col, col + 4) + getRowSum(row + 2, col, col + 2) +
          getRowSum(row + 4, col, col + 4) +
          getColSum(col + 4, row + 1, row + 3) + field[row + 3][col];
  } else {
    res = solve(row + 2, col + 2, k - 4);
    res += getRowSum(row, col, col + k - 2) +
           getColSum(col + k - 1, row, row + k - 2) +
           getRowSum(row + k - 1, col, col + k - 1) +
           getColSum(col, row + 2, row + k - 2) + field[row + 2][col + 1];
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> field[i][j];
  for (int i = 0; i < n; i++) {
    rowsum[i][0] = field[i][0];
    for (int j = 1; j < m; j++) rowsum[i][j] = rowsum[i][j - 1] + field[i][j];
  }
  for (int j = 0; j < m; j++) {
    colsum[j][0] = field[0][j];
    for (int i = 1; i < n; i++) colsum[j][i] = colsum[j][i - 1] + field[i][j];
  }
  int best = -inf;
  memset(dp, 0x3f, sizeof(dp));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      for (int k = 3;; k += 2) {
        int cur = solve(i, j, k);
        ;
        ;
        ;
        ;
        if (cur == inf)
          break;
        else
          best = max(best, cur);
      }
  cout << best << endl;
  return 0;
}
