#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++)
    {
      for(haba = 0 ; haba <= input_w - 3 ; haba++)
      {
        for(moving_tate = 0 ; moving_tate <= input_d - 3 - okuyuki ; moving_tate++)
        {
          for(moving_yoko = 0 ; moving_yoko <= input_w - 3 - haba ; moving_yoko++, sum_deepth = 0)
          {
            for(counter_i = moving_tate ; counter_i <= okuyuki + 2 + moving_tate ; counter_i++)
            {
              for(counter_j = moving_yoko ; counter_j <= haba + 2 + moving_yoko ; counter_j++)
              {
                if(moving_tate < counter_i && counter_i < okuyuki + 2 + moving_tate)
                {
                  if(moving_yoko < counter_j && counter_j < haba + 2 + moving_yoko)
                  {
                    sum_deepth += input_e[counter_i][counter_j];
                    if(in_max_height < input_e[counter_i][counter_j])
                    {
                      in_max_height = input_e[counter_i][counter_j];
                    }
                  }
                  else
                  {
                    if(out_min_height > input_e[counter_i][counter_j])
                    {
                      out_min_height = input_e[counter_i][counter_j];
                    }
                  }
                }
                else
                {
                  if(out_min_height > input_e[counter_i][counter_j])
                  {
                    out_min_height = input_e[counter_i][counter_j];
                  }
                }
              }
            }
            if(out_min_height <= in_max_height)
            {
              in_max_height = 0;
              out_min_height = 9;
              continue;
            }
            if(max_deepth < sum_deepth)
            {
              max_deepth = sum_deepth;
            }
          }
        }
      }
    }

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

