// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int solve_testcase() {
    int H, W; scanf("%d%d", &H, &W);
    if(H == 0 and W == 0) return 1;

    vector< vector<int> > board(H, vector<int>(W));
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            scanf("%d", &board[i][j]);
        }
    }

    int ans = 0;
    for(int h=3; h<=H; h++) {
        for(int w=3; w<=W; w++) {
            for(int lx=0; lx<H-h+1; lx++) {
                for(int ly=0; ly<W-w+1; ly++) {
                    int max_inside = -1, min_edge = 100, sum = 0;
                    for(int x=lx; x<lx+h; x++) {
                        for(int y=ly; y<ly+w; y++) {
                            bool edge = false;
                            edge |= (x == lx or x == lx+h-1);
                            edge |= (y == ly or y == ly+w-1);
                            if(edge) chmin(min_edge, board[x][y]);
                            else {
                                chmax(max_inside, board[x][y]);
                                sum += board[x][y];
                            }
                        }
                    }
                    if(max_inside < min_edge) {
                        int cand = min_edge * (h-2) * (w-2) - sum;
                        chmax(ans, cand);
                    }
                }
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

int main() {
    while(!solve_testcase());
    return 0;
}

