#include <bits/stdc++.h>
using namespace std;
int x[510][510], row[510][510], col[510][510];
int n, m, ans;
void calc_ans(int sx, int sy) {
  int up = sx - 1, down = sx + 1, left = sy - 1, right = sy + 1;
  int t = x[sx][sy], sum = x[sx][sy];
  while (up >= 1 && down <= n && left >= 1 && right <= m) {
    int add = row[up][right] - row[up][left] + col[right][down] -
              col[right][up] + row[down][right - 1] - row[down][left - 1] +
              col[left][down - 1] - col[left][up - 1];
    t = sum - t + add - x[up + 1][left];
    sum += add;
    ans = max(ans, t);
    up--;
    down++;
    left--;
    right++;
  }
}
void init() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> x[i][j];
      row[i][j] = row[i][j - 1] + x[i][j];
      col[j][i] = col[j][i - 1] + x[i][j];
    }
}
void solve() {
  ans = -250000000;
  for (int i = 2; i <= n - 1; i++)
    for (int j = 2; j <= m - 1; j++) calc_ans(i, j);
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  init();
  solve();
  return 0;
}
