#include <stdio.h>

int main()
{
  int input_d, input_w;
  int input_e[10][10];
  int okuyuki, haba;
  int moving_yoko, moving_tate;
  int counter_i, counter_j;

  for( ; ; )
  {
    int in_max_height = 0, out_min_height = 9;
    int sum_deepth = 0, max_deepth = 0;

    scanf("%d %d", &input_d, &input_w);
    if(input_d == 0 && input_w == 0)
      break;

    for(counter_i = 0 ; counter_i < input_d ; counter_i++)
    {
      for(counter_j = 0 ; counter_j < input_w ; counter_j++)
        scanf("%d", &input_e[counter_i][counter_j]);
    }

    for(okuyuki = 0 ; okuyuki <= input_d - 3 ; okuyuki++)
    {
      //printf("OK01\n");
      for(haba = 0 ; haba <= input_w - 3 ; haba++)
      {
        //printf("OK02\n");
        for(moving_tate = 0 ; moving_tate <= input_d - 3 - okuyuki ; moving_tate++)
        {
          //printf("OK03\n");
          for(moving_yoko = 0 ; moving_yoko <= input_w - 3 - haba ; moving_yoko++)
          {
            //printf("OK04\n");
            for(counter_i = moving_tate ; counter_i <= okuyuki + 2 + moving_tate ; counter_i++)
            {
              //printf("OK05\n");
              for(counter_j = moving_yoko ; counter_j <= haba + 2 + moving_yoko ; counter_j++)
              {
                //printf("OK06\n");
                if(moving_tate < counter_i && counter_i < okuyuki + 2 + moving_tate)
                {
                  //printf("OK07\n");
                  if(moving_yoko < counter_j && counter_j < haba + 2 + moving_yoko)
                  {
                    //printf("OK08\n");
                    if(in_max_height < input_e[counter_i][counter_j])
                    {
                      //printf("OK09\n");
                      in_max_height = input_e[counter_i][counter_j];
                    }
                  }
                  else
                  {
                    //printf("OK10\n");
                    if(out_min_height > input_e[counter_i][counter_j])
                    {
                      //printf("OK11\n");
                      out_min_height = input_e[counter_i][counter_j];
                    }
                  }
                }
                else
                {
                  //printf("OK12\n");
                  if(out_min_height > input_e[counter_i][counter_j])
                  {
                    //printf("OK13\n");
                    out_min_height = input_e[counter_i][counter_j];
                  }
                }
                //printf("in_max_height:%d\n", in_max_height);
                //printf("out_min_height:%d\n", out_min_height);
                //printf("okuyuki:%d\n", okuyuki + 3);
                //printf("haba:%d\n", haba + 3);
                //printf("moving_tate:%d\n", moving_tate);
                //printf("moving_yoko:%d\n", moving_yoko);
                //printf("counter_i:%d\n", counter_i);
                //printf("counter_j:%d\n", counter_j);
                //printf("------------------------\n");
              }
            }
            if(out_min_height <= in_max_height)
            {
              //printf("OK14\n");
              in_max_height = 0;
              out_min_height = 9;
              continue;
            }
            for(counter_i = moving_tate + 1 ; counter_i < okuyuki + 2 + moving_tate ; counter_i++)
            {
              //printf("sum_deepth:%d\n", sum_deepth);
              //printf("OK15\n");
              for(counter_j = moving_yoko + 1 ; counter_j < haba + 2 + moving_yoko ; counter_j++)
              {
                sum_deepth = sum_deepth + (out_min_height - input_e[counter_i][counter_j]);
                //printf("sum_deepth:%d\n", sum_deepth);
              }
            }
            if(max_deepth < sum_deepth)
            {
              //printf("OK16\n");
              max_deepth = sum_deepth;
            }
            sum_deepth = 0;
          }
        }
      }
    }

    printf("%d\n", max_deepth);
  }
  return 0;
}



Measured memory_bytes: 2048