#include <bits/stdc++.h>
using namespace std;
const int N = 550;
const long long MMM = 99999999999999ll;
int a[N][N];
long long sum[N][N];
long long s[N][N], ss[N][N];
int n, m;
inline long long get_sum_sq(int i2, int j2, int k) {
  int i1 = i2 - k + 1;
  int j1 = j2 - k + 1;
  long long ret = sum[i2][j2];
  if (i1 > 0) ret -= sum[i1 - 1][j2];
  if (j1 > 0) ret -= sum[i2][j1 - 1];
  if (i1 > 0 && j1 > 0) ret += sum[i1 - 1][j1 - 1];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  memset(sum, 0, sizeof(sum));
  sum[0][0] = a[0][0];
  for (int i = 1; i < m; ++i) {
    sum[0][i] = sum[0][i - 1] + a[0][i];
  }
  for (int i = 1; i < n; ++i) {
    sum[i][0] = sum[i - 1][0] + a[i][0];
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] + a[i][j] - sum[i - 1][j - 1];
    }
  }
  long long ans = -MMM;
  memset(s, 0, sizeof(s));
  for (int i = 2; i < n; ++i) {
    for (int j = 2; j < m; ++j) {
      s[i][j] = get_sum_sq(i, j, 3) - a[i - 1][j - 1] - a[i - 1][j - 2];
      if (ans < s[i][j]) ans = s[i][j];
    }
  }
  int t = min(n, m);
  for (int k = 5; k <= t; k += 2) {
    memset(ss, sizeof(ss), 0);
    for (int i = k - 1; i < n; ++i) {
      for (int j = k - 1; j < m; ++j) {
        ss[i][j] =
            get_sum_sq(i, j, k) - s[i - 1][j - 1] - a[i - k + 2][j - k + 1];
        if (ans < ss[i][j]) ans = ss[i][j];
      }
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        s[i][j] = ss[i][j];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
