#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	while(1){
		int d,w;
		cin >> d >> w;
		if( d == 0 ) break;
		int e[10][10];
		rep(i,0,d) rep(j,0,w) cin >> e[i][j];

		ll ans = 0;
		for(int s_d = 0 ; s_d < d ; s_d++ ){
			for(int s_w = 0 ; s_w < w ; s_w++ ){
				for(int g_d = s_d+2 ; g_d < d; g_d++ ){
					for(int g_w = s_w+2 ; g_w < w ; g_w++){
						int min_h = INF;

						for(int j = s_w ; j <= g_w ; j++ ){
							min_h = min(e[s_d][j] , min_h );
							min_h = min(e[g_d][j] , min_h );
						}


						for(int i = s_d ; i <= g_d ; i++ ){
							min_h = min(e[i][s_w] , min_h );
							min_h = min(e[i][g_w] , min_h );
						}

						bool f = 0;
						ll sum = 0;
						for(int i = s_d+1; i <= g_d-1 ; i++ ){
							for( int j = s_w+1 ; j <= g_w-1 ; j++ ){
								if( e[i][j] >= min_h ) f = 1;
								sum += min_h - e[i][j];
							}
						}

						//cout << s_d << " " << s_w << " " << g_d << " " << g_w << " " << min_h << " " << sum << endl;
						if( f ) continue;

						ans = max( ans , sum );
					}
				}
			}
		}
		cout << ans << endl;
	}
	ret 0;
}
