#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[500][500];
int t[500][500];
int s[500][500];
bool was[500][500];
int sum(int r, int c) {
  if (was[r][c]) return s[r][c];
  was[r][c] = true;
  int res = 0;
  for (int i = r; i >= 0; i = (i & (i + 1)) - 1)
    for (int j = c; j >= 0; j = (j & (j + 1)) - 1) res += t[i][j];
  return s[r][c] = res;
}
void update(int r, int c, int d) {
  for (int i = r; i < n; i = i | (i + 1))
    for (int j = c; j < m; j = j | (j + 1)) t[i][j] += d;
}
int sq(int i, int j, int a) {
  int res = sum(i + a, j + a);
  if (i - a > 0) res -= sum(i - a - 1, j + a);
  if (j - a > 0) res -= sum(i + a, j - a - 1);
  if (i - a > 0 && j - a > 0) res += sum(i - a - 1, j - a - 1);
  return res;
}
int main() {
  scanf("%i%i", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      scanf("%i", &a[i][j]);
      update(i, j, a[i][j]);
    }
  int ans = -1e9;
  for (int i = 1; i < n - 1; i++)
    for (int j = 1; j < m - 1; j++) {
      int r = i, c = j - 1;
      int s = sq(i, j, 1) - a[i][j] - a[r][c];
      ans = max(ans, s);
      int b = 2;
      while (i - b >= 0 && j - b >= 0 && i + b < n && j + b < m) {
        r--;
        c--;
        s = sq(i, j, b) - s - a[r][c];
        ans = max(ans, s);
        b++;
      }
    }
  cout << ans;
  return 0;
}
