#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i = (a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = false;

int H, W;
int e[10][10];

int main() {
	while (cin >> H >> W, H || W) {
		REP(i, H) REP(j, W) scanf("%d", &e[i][j]);
		if (debug) putchar('@');

		int ans = 0;
		FOR(h, 3, H + 1) FOR(w, 3, W + 1) { // 1-index
			REP(y, H - h + 1) REP(x, W - w + 1) {
				int mi = INF, ma = 0;
				int sum = 0;
				REP(i, h) REP(j, w) {
					int ny = y + i, nx = x + j;
					if (i == 0 || j == 0 || i == h - 1 || j == w - 1) {
						chmin(mi, e[ny][nx]);
					}
					else {
						chmax(ma, e[ny][nx]);
						sum -= e[ny][nx];
					}
				}
				sum += (h - 2) * (w - 2) * mi;
				if (mi <= ma) continue;
				chmax(ans, sum);
			}
		}
		cout << ans << endl;
	}
	return 0;
}
