#include <bits/stdc++.h>
using namespace std;
int tab[512][512];
int row[512][512];
int col[512][512];
inline int line(int r0, int c0, int r1, int c1) {
  if (r1 < r0) return 0;
  if (c1 < c0) return 0;
  if (r0 == r1) {
    return col[r1][c1 + 1] - col[r0][c0];
  } else {
    return row[r1 + 1][c1] - row[r0][c0];
  }
}
inline int box(int r0, int c0, int r1, int c1) {
  return line(r0, c0, r0, c1) + line(r1, c0, r1, c1) +
         line(r0 + 1, c0, r1 - 1, c0) + line(r0 + 1, c1, r1 - 1, c1);
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      scanf("%d", &tab[i][j]), col[i][j + 1] = col[i][j] + tab[i][j],
                                          row[i + 1][j] = row[i][j] + tab[i][j];
  long long score;
  long long best = -(1ll << 50ll);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      score = 0;
      for (int k = 1; i - k >= 0 and j - k >= 0 and i + k < n and j + k < m;
           k += 2) {
        score += box(i - k, j - k, i + k, j + k) - tab[i - k + 1][j - k];
        best = max(best, score);
        if (j - k > 0) score += tab[i - k][j - k - 1];
      }
      score = tab[i][j];
      for (int k = 2; i - k >= 0 and j - k >= 0 and i + k < n and j + k < m;
           k += 2) {
        score += box(i - k, j - k, i + k, j + k) - tab[i - k + 1][j - k] +
                 tab[i - k + 2][j - k + 1];
        best = max(best, score);
      }
    }
  printf("%d\n", best);
}
