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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int h, w;
int f[11][11];

int main() {
    vector<int> res;
    while (cin >> h >> w and h) {
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> f[i][j];
            }
        }
        int cnt = 0;
        for (int i = 3; i <= h; i++) {
            for (int j = 3; j <= w; j++) {
                for (int k = 0; k <= h - i; k++) {
                    for (int l = 0; l <= w - j; l++) {
                        // cout << k << " " << l << endl;
                        // cout << "H size:" << i << " W size:" << j << endl;
                        int mi = inf;
                        for (int m = 0; m < j; m++) {
                            mi = min(mi, f[k][l + m]);
                            mi = min(mi, f[k + i - 1][l + m]);
                        }
                        for (int m = 0; m < i; m++) {
                            mi = min(mi, f[k + m][l]);
                            mi = min(mi, f[k + m][l + j - 1]);
                        }
                        int ma = -1;
                        int sum = 0;                        
                        for (int m = 1; m < i - 1; m++) {
                            for (int n = 1; n < j - 1; n++) {
                                ma = max(ma, f[k + m][l + n]);
                                sum += mi - f[k + m][l + n];
                            }
                        }
                        // dump(ma);
                        if (mi > ma) {
                            cnt = max(cnt, sum);
                        }
                    }
                }
            }
        }
        res.push_back(cnt);
    }
    for (int i = 0; i < (int)res.size(); i++) {
        dump(res[i]);
    }
    return 0;
}
