#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)

signed main() {
	for (int d, w; cin >> d >> w && d;) {
		vector<vector<int>> e(d, vector<int>(w));
		rep(i, 0, d)rep(j, 0, w)cin >> e[i][j];
		int ans = 0;
		rep(i, 0, d)rep(j, 0, w)rep(ii, i + 2, d)rep(jj, j + 2, w) {
			int m = e[i][j];
			rep(ci, i, ii + 1) {
				m = min(m, e[ci][j]);
				m = min(m, e[ci][jj]);
			}
			rep(cj, j, jj + 1) {
				m = min(m, e[i][cj]);
				m = min(m, e[ii][cj]);
			}
			int k = e[i + 1][j + 1];
			int sum = 0;
			rep(ci, i + 1, ii)rep(cj, j + 1, jj) {
				k = max(k, e[ci][cj]);
				sum += m - e[ci][cj];
			}
			if (k >= m)continue;
			ans = max(sum, ans);
		}
		cout << ans << endl;
	}
	return 0;
}
