#include <bits/stdc++.h>
using namespace std;
const unsigned kMaxN = 500;
const unsigned kMaxM = 500;
typedef int Table[kMaxN][kMaxM];
int Solve(unsigned n, unsigned m, Table table) {
  int partial_row_sum[kMaxN][kMaxM + 1], partial_col_sum[kMaxN + 1][kMaxM];
  for (unsigned row = 0; row < n; ++row) {
    partial_row_sum[row][0] = 0;
    for (unsigned col = 0; col < m; ++col) {
      partial_row_sum[row][col + 1] =
          partial_row_sum[row][col] + table[row][col];
    }
  }
  for (unsigned col = 0; col < m; ++col) {
    partial_col_sum[0][col] = 0;
    for (unsigned row = 0; row < n; ++row) {
      partial_col_sum[row + 1][col] =
          partial_col_sum[row][col] + table[row][col];
    }
  }
  int answer = numeric_limits<int>::min();
  Table buffer[3];
  for (unsigned row = 0; row < n; ++row)
    for (unsigned col = 0; col < m; ++col)
      buffer[0][row][col] = table[row][col];
  unsigned current_buffer = 1;
  for (unsigned size = 3; size <= min(n, m); size += 2) {
    for (unsigned row = 0; row + size <= n; ++row) {
      for (unsigned col = 0; col + size <= m; ++col) {
        int a = partial_row_sum[row][col + size] - partial_row_sum[row][col];
        int b = partial_col_sum[row + size][col + size - 1] -
                partial_col_sum[row + 1][col + size - 1];
        int c = partial_row_sum[row + size - 1][col + size - 1] -
                partial_row_sum[row + size - 1][col];
        int d = size > 3 ? partial_col_sum[row + size - 1][col] -
                               partial_col_sum[row + 2][col]
                         : 0;
        int e = size > 3 ? table[row + 2][col + 1] : 0;
        int f = size > 3
                    ? buffer[(current_buffer - 2 + 3) % 3][row + 2][col + 2]
                    : 0;
        buffer[current_buffer][row][col] = a + b + c + d + e + f;
        if (buffer[current_buffer][row][col] > answer)
          answer = buffer[current_buffer][row][col];
      }
    }
    current_buffer = (current_buffer + 1) % 3;
  }
  return answer;
}
int main() {
  unsigned n, m;
  Table table;
  scanf("%u%u", &n, &m);
  for (unsigned row = 0; row < n; ++row) {
    for (unsigned col = 0; col < m; ++col) scanf("%d", &table[row][col]);
  }
  printf("%d\n", Solve(n, m, table));
  return 0;
}
