#include <bits/stdc++.h>
using namespace std;
int a[555][555];
int query(int r1, int c1, int r2, int c2) {
  return a[r2][c2] - a[r1 - 1][c2] - a[r2][c1 - 1] + a[r1 - 1][c1 - 1];
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int(i) = (1); (i) <= (n); ++(i))
    for (int(j) = (1); (j) <= (m); ++(j)) {
      scanf("%d", &a[i][j]);
      a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
    }
  int ans = -1e9;
  for (int(i) = (1); (i) <= (n - 2); ++(i))
    for (int(j) = (1); (j) <= (m - 2); ++(j)) {
      pair<int, int> center = make_pair(i + 1, j + 1);
      pair<int, int> topLeft = make_pair(i, j);
      int size = 3;
      int sum = query(topLeft.first, topLeft.second, topLeft.first + 2,
                      topLeft.second + 2);
      sum -= query(center.first, center.second, center.first, center.second);
      sum -= query(topLeft.first + 1, topLeft.second, topLeft.first + 1,
                   topLeft.second);
      while (1) {
        ans = max(ans, sum);
        size += 2;
        topLeft = make_pair(topLeft.first - 1, topLeft.second - 1);
        if (topLeft.first < 1 || topLeft.second < 1 ||
            topLeft.first + size - 1 > n || topLeft.second + size - 1 > m)
          break;
        sum = query(topLeft.first, topLeft.second, topLeft.first + size - 1,
                    topLeft.second + size - 1) -
              sum;
        sum -= query(topLeft.first + 1, topLeft.second, topLeft.first + 1,
                     topLeft.second);
      }
    }
  printf("%d\n", ans);
  return 0;
}
