#include <bits/stdc++.h>
using namespace std;

int main(void){
	int d, w;
	int di[] = {1,1,1,0,-1,-1,-1,0};
	int dj[] = {1,0,-1,-1,-1,0,1,1};
	while(cin >> d >> w, d+w){
		vector<int> e[d+2];
		e[0].resize(w+2); e[d+1].resize(w+2);
		for(int i = 1; i <= d; ++i){
			e[i].resize(w+2);
			for (int j = 1; j <= w; ++j){
				cin >> e[i][j];
			}
		}
		// for(int i = 0; i <= d+1; ++i){
		// 	for (int j = 0; j <= w+1; ++j){
		// 		cout << e[i][j] << " ";
		// 	}
		// 	cout << endl;
		// }
		int ans = 0;
		for(int i = 1; i <= d; ++i){
			for (int j = 1; j <= w; ++j){
				for(int k = 3; i+k <= d+1; ++k){
					for (int l = 3; j+l <= w+1; ++l){
						int m = 10;
						for(int kk = 0; kk < k; ++kk){
							m = min(m, e[i+kk][j]);
							m = min(m, e[i+kk][j+l-1]);
						}
						for(int ll = 0; ll < l; ++ll){
							m = min(m, e[i][j+ll]);
							m = min(m, e[i+k-1][j+ll]);
						}
						bool a = true;
						int tmp = 0;
						for(int kk = 1; kk < k-1; ++kk){
							for(int ll = 1; ll < l-1; ++ll){
								if(e[i+kk][j+ll]>=m) a = false;
								tmp += m-e[i+kk][j+ll];
							}
						}
						if(a) ans = max(ans, tmp);
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}
