#include <bits/stdc++.h>
using namespace std;
int s[510][510], d[2][510][510];
int sum1[510][510], sum2[510][510];
void init(int n, int m) {
  for (int i = 0; i < m; ++i) sum1[0][i] = s[0][i];
  for (int i = 1; i < n; ++i)
    for (int j = 0; j < m; ++j) sum1[i][j] = sum1[i - 1][j] + s[i][j];
  for (int i = 0; i < n; ++i) sum2[i][0] = s[i][0];
  for (int i = 1; i < m; ++i)
    for (int j = 0; j < n; ++j) sum2[j][i] = sum2[j][i - 1] + s[j][i];
}
int pre, cur;
int dp(int x, int y, int w) {
  if (w == 1) return d[cur][x][y] = s[x][y];
  if (w == 3)
    return d[cur][x][y] = s[x][y] + s[x][y + 1] + s[x][y + 2] +
                          s[x + 1][y + 2] + s[x + 2][y + 2] + s[x + 2][y + 1] +
                          s[x + 2][y];
  int res = 0;
  res += sum2[x][y + w - 2];
  if (y > 0) res -= sum2[x][y - 1];
  res += sum1[x + w - 1][y] - sum1[x][y];
  res += sum2[x + w - 1][y + w - 1] - sum2[x + w - 1][y];
  res += sum1[x + w - 2][y + w - 1];
  if (x > 0) res -= sum1[x - 1][y + w - 1];
  res += (s[x + 2][y + 1] - s[x + 1][y]);
  return d[cur][x][y] = res + d[pre][x + 2][y + 2];
}
int main() {
  int n, m, res = -1;
  bool find = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf("%d", &s[i][j]);
  init(n, m);
  int nm = min(n, m);
  pre = 0;
  cur = 1;
  for (int i = 1; i <= nm; i += 4) {
    cur = pre;
    pre = 1 - pre;
    for (int j = 0; j <= n - i; ++j) {
      for (int k = 0; k <= m - i; ++k) {
        dp(j, k, i);
        if (i == 1) continue;
        if (!find || res < d[cur][j][k]) res = d[cur][j][k];
        find = 1;
      }
    }
  }
  pre = 0;
  cur = 1;
  for (int i = 3; i <= nm; i += 4) {
    cur = pre;
    pre = 1 - pre;
    for (int j = 0; j <= n - i; ++j) {
      for (int k = 0; k <= m - i; ++k) {
        dp(j, k, i);
        if (!find || res < d[cur][j][k]) res = d[cur][j][k];
        find = 1;
      }
    }
  }
  printf("%d\n", res);
  return 0;
}
