#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    res = accumulate(a.begin(),a.end(),0LL) - N;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    
    int d,w;
    while(cin >> d >> w,d){
        auto e = make_v<int>(d,w);
        for(auto& vec:e) for(auto& in:vec) cin >> in;

        int ans = 0;
        for(int uly = 0; uly < d; uly++){
            for(int ulx = 0; ulx < w; ulx++){
                for(int lry = uly+2; lry < d; lry++){
                    for(int lrx = ulx+2; lrx < w; lrx++){
                        int minwall = INF;
                        for(int z = uly; z <= lry; z++) minwall = min(minwall,e[z][ulx]);
                        for(int z = uly; z <= lry; z++) minwall = min(minwall,e[z][lrx]);
                        for(int z = ulx; z <= lrx; z++) minwall = min(minwall,e[uly][z]);
                        for(int z = ulx; z <= lrx; z++) minwall = min(minwall,e[lry][z]);
                        
                        int T = 0;
                        for(int iny = uly+1; iny < lry; iny++){
                            for(int inx = ulx+1; inx < lrx; inx++){
                                if(minwall <= e[iny][inx]) T = -INF;
                                T += minwall - e[iny][inx];
                            }
                        }
                        ans = max(ans,T);
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3204