#include <stdio.h>

int max(int a, int b){
  if (a > b) {
    return a;
  } else {
    return b;
  }
}
int min(int a, int b ){
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

int main(void){
  int d,w;
  int stage[10][10];
  int counter;
  int frmin;
  int depsum,depmax;
  int depsummax;
  //int allsum[10][10];
  scanf("%d%d",&d,&w );
  while (d != 0) {
    for (int i = 0; i < d; i++) {
      for (int j = 0; j < w; j++) {
        scanf("%d",&stage[i][j]);
        //allsum[i][j] = 0
      }
    }

    depsummax = 0;
    /*
    for (int i = 1; i < d+1; i++) {
      for (int j = 1; j < w+1; j++) {
        allsum[i][j] = allsum[i][j-1] + stage[i-1][j-1];
      }
    }
    for (int i = 1; i < w+1; i++) {
      for (int j = 1; j < d+1; j++) {
        allsum[j][i] = allsum[j-1][i] + stage[j-1][i-1];
      }
    }
    */
    for (int i = 0; i < d-2; i++) {
      for (int j = 0; j < w-2; j++) { //始点
        for (int k = i+2; k < d; k++) {
          for (int l = j+2; l < w; l++) { // 終点
            depmax = 0;
            depsum = 0;
            frmin = 1000;
            counter = 0; //initialize
            for (int m = i; m <= k; m++) {
              for (int n = j; n <= l; n++) {
                if (i<m&&m<k && j<n&&n<l) {
                  depsum += stage[m][n];
                  counter++;
                  depmax = max(depmax,stage[m][n]);
                } else {
                  frmin = min(frmin,stage[m][n]);
                }
              }
            }
            if (depmax < frmin) {
              depsum = frmin * counter - depsum;
              depsummax = max(depsummax,depsum);
            }
          }
        }
      }
    }
    
    printf("%d\n",depsummax );
    scanf("%d%d", &d,&w);
  }
  return 0;
}

