#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
ll inf = 1e18;

ll d, w;
ll field[11][11];
int main() {
	while (cin >> d >> w && d > 0) {
		REP(i, 0, d) {
			REP(j, 0, w) {
				cin >> field[i][j];
			}
		}
		ll ans = 0;
		REP(y1, 0, d) REP(x1, 0, w) REP(y2, y1 + 2, d) REP(x2, x1 + 2, w) {
			ll mx = inf;
			REP(y, y1, y2 + 1) {
				mx = min(mx, field[y][x1]);
				mx = min(mx, field[y][x2]);
			}
			REP(x, x1, x2 + 1) {
				mx = min(mx, field[y1][x]);
				mx = min(mx, field[y2][x]);
			}
			ll sum = 0;
			bool ok = true;
			REP(y, y1 + 1, y2) {
				REP(x, x1 + 1, x2) {
					if (mx - field[y][x] <= 0) {
						ok = false;
						break;
					}
					sum += mx - field[y][x];
				}
				if (!ok) break;
			}
			if (ok) ans = max(ans, sum);
		}
		p(ans);
	}

	return 0;
}
