#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int h, w; cin >> h >> w;
    if(h == 0 && w == 0) break;
    vvi a(h);
    REP(i, h) {
      a[i].resize(w);
      REP(j, w) {
        cin >> a[i][j];
      }
    }
    int ma = 0;
    FOR(i, 3, h+1) {
      FOR(j, 3, w+1) {
        REP(k, h-i+1) {
          REP(l, w-j+1) {
            int mi = INF;
            FOR(m, k, k+i) {
              FOR(n, l, l+j) {
                if(m == k || m == k+i-1 || n == l || n == l+j-1) {
                  mi = min(mi, a[m][n]);
                }
              }
            }
            int sz = 0;
            bool ok = true;
            FOR(m, k+1, k+i-1) {
              FOR(n, l+1, l+j-1) {
                if(a[m][n] >= mi) {
                  ok = false;
                  break;
                } else {
                  sz += mi - a[m][n];
                }
              }
              if(!ok) {
                sz = 0;
                break;
              }
            }
            ma = max(ma, sz);
          }
        }
      }
    }
    cout << ma << endl;
  }
}

