var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
   var [d, w] = arr.shift().split(" ").map(Number);
   if (d == 0 && w == 0) break;
   var yx = [];
   for (var i = 0; i < d; i++) yx[i] = arr.shift().split(" ").map(Number);
   
   var sumFn = function(y, x, yy, xx) {
      var min = Infinity;
      for (var i = y; i <= yy; i++) {
         for (var j = x; j <= xx; j++) {
            if (i == y || j == x || i == yy || j == xx) min = Math.min(min, yx[i][j]);
         }
      }
      var sum = 0;
      for (var i = y; i <= yy; i++) {
         for (var j = x; j <= xx; j++) {
            if (i == y || j == x || i == yy || j == xx) continue;
            if (min <= yx[i][j]) return 0;
            sum += min - yx[i][j];
         }
      }
      return sum;
   };
   
   var max = 0;
   for (var y = 0; y < d - 2; y++) {
      for (var x = 0; x < w - 2; x++) {
         for (var yy = y + 2; yy < d; yy++) {
            for (var xx = x + 2; xx < w; xx++) {
               max = Math.max(max, sumFn(y, x, yy, xx));
            }
         }
      }
   }
   console.log(max);
}
