#include <bits/stdc++.h>
using namespace std;
template <class T, class D>
class Range {
  class It {
   public:
    It(const T& v, const T& e, const D& s) : v_(v), e_(e), s_(s), end_(false) {
      checkEnd();
    };
    T operator*() { return v_; }
    It& operator++() {
      if (!end_) {
        v_ += s_;
        checkEnd();
      }
      return *this;
    }
    It operator++(int) {
      It r = *this;
      ++r;
      return r;
    }
    bool operator!=(const It& o) const {
      return (end_ && !o.end_) || (!end_ && o.end_) || (!end_ && (v_ != o.v_));
    }

   private:
    void checkEnd() {
      bool pos = (s_ > static_cast<D>(0));
      bool eq = v_ == e_;
      bool more = v_ > e_;
      end_ = eq || (more && pos) || (!more && !pos);
    }
    T v_;
    T e_;
    D s_;
    bool end_;
  };

 public:
  Range(const T& b, const T& e, const D& s) : b_(b), e_(e), s_(s){};
  It begin() const { return It{b_, e_, s_}; }
  It end() const { return It{e_, e_, s_}; }

 private:
  T b_;
  T e_;
  D s_;
};
template <typename T>
Range<T, T> R(const T& e) {
  typedef decltype(e - e) D;
  return Range<T, T>{static_cast<T>(0), e, static_cast<D>(1)};
}
template <typename T>
Range<T, T> R(const T& b, const T& e) {
  typedef decltype(e - b) D;
  return Range<T, T>{b, e, static_cast<D>(1)};
}
template <typename T, typename D>
Range<T, D> R(const T& b, const T& e, const D& d) {
  return Range<T, D>{b, e, d};
}
template <class T>
T read() {
  T r;
  cin >> r;
  return r;
}
vector<vector<int>> S;
vector<vector<int>> F;
vector<vector<vector<int>>> DP;
int N, M;
int sq(int i, int j, int s) {
  return S[i + s][j + s] - S[i][j + s] - S[i + s][j] + S[i][j];
}
inline int to_i(int s) { return (s / 2) - 1; }
int INF = 1000000000;
int RES = -INF;
int dp(int i, int j, int s) {
  int ss = to_i(s);
  int& res = DP[i][j][ss];
  if (res != INF) {
    return res;
  }
  if (s != 3) {
    res = sq(i, j, s) - F[i + 1][j] - dp(i + 1, j + 1, s - 2);
  } else {
    res = sq(i, j, s) - F[i + 1][j] - F[i + 1][j + 1];
  }
  RES = max(RES, res);
  return res;
}
int main() {
  N = read<int>();
  M = read<int>();
  S.resize(N + 1);
  F.resize(N);
  DP.resize(N);
  for (int i : R(N)) {
    S[i].resize(M + 1);
    F[i].resize(M);
    DP[i].resize(M);
  }
  S[N].resize(M + 1);
  for (int i : R(N)) {
    for (int j : R(M)) {
      F[i][j] = read<int>();
      DP[i][j].resize(to_i(min(N - i, M - j) + 1) + 1, INF);
    }
  }
  for (int i : R(N + 1)) {
    S[i][0] = 0;
  }
  for (int j : R(M + 1)) {
    S[0][j] = 0;
  }
  for (int i : R(N)) {
    for (int j : R(M)) {
      S[i + 1][j + 1] = F[i][j] + S[i][j + 1] + S[i + 1][j] - S[i][j];
    }
  }
  for (int i : R(N)) {
    for (int j : R(M)) {
      for (int s : R(3, min(N - i, M - j) + 1, 2)) {
        dp(i, j, s);
      }
    }
  }
  cout << RES;
  return 0;
}
