#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b; return true;}return false;}
int d,w,field[15][15];
int main(){
  while(1){
    int ans=-1;
    cin >> d >> w;
    if(d==0 && w==0) break;
    for(int i=0;i<d;i++)for(int j=0;j<w;j++) cin >> field[j][i];
    for(int i=1;i<=w-2;i++)for(int j=1;j<=d-2;j++)for(int k=1;k<=w-2;k++)for(int l=1;l<=d-2;l++){
      int circuit_min=114514;
      //cout << "(" << i << "," << j<< ")" << endl;
      //cout << "(" << k << "," <<l << ")" << endl;
      for(int x=i-1;x<=k+1;x++)for(int y=j-1;y<=l+1;y++){
        if((i<=x && x<=k) && (j<=y && y<=l));
        else chmin(circuit_min,field[x][y]);
      }
      //cout << "circuit_min:" << circuit_min << endl;
      int in_max = -1;
      for(int x=i;x<=k;x++)for(int y=j;y<=l;y++){
        chmax(in_max,field[x][y]);
        //cout << field[x][y] << endl;
      }
      //cout <<  "in_max:" << in_max << endl;
      if(circuit_min>in_max){
        int sum=0;
        for(int x=i;x<=k;x++)for(int y=j;y<=l;y++) sum+=circuit_min-field[x][y];
        chmax(ans,sum);
      }
      //cout << "ans;" << ans << endl;
    }
    if(ans==-1) cout << "0" << endl;
    else cout << ans << endl;
  }
  return 0;
}

