Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		d, w := io.NextInt(), io.NextInt()
		if d == 0 {
			break
		}
		e := make([][]int, d)
		for i := 0; i < d; i++ {
			e[i] = make([]int, w)
			for j := 0; j < w; j++ {
				e[i][j] = io.NextInt()
			}
		}
		ans := 0
		for i := 0; i < d-2; i++ {
			for j := 0; j < w-2; j++ {
				for k := i + 2; k < d; k++ {
					for l := j + 2; l < w; l++ {
						ans = intMax(vol(e, i, j, k, l), ans)
					}
				}
			}
		}
		io.Println(ans)
	}
}

func vol(e [][]int, a, b, c, d int) int {
	outer := 10
	for i := a; i <= c; i++ {
		outer = intMin(e[i][b], outer)
		outer = intMin(e[i][d], outer)
	}
	for j := b; j <= d; j++ {
		outer = intMin(e[a][j], outer)
		outer = intMin(e[c][j], outer)
	}
	a++
	b++
	vol := 0
	for i := a; i < c; i++ {
		for j := b; j < d; j++ {
			if e[i][j] >= outer {
				return 0
			}
			vol += outer - e[i][j]
		}
	}
	return vol
}

func intMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func intMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

Python: import sys
# python template for atcoder1
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def calcVolume(L, R, T, B, min_wall):
    '''
    池の体積を計算
    '''
    ret = 0
    for w in range(L, R+1):
        for h in range(B, T+1):
            ret += (min_wall-garden[h][w])
    return ret


def pondsVolume(L, R, T, B):
    '''
    池の体積をreturn
    池を作れないなら-1
    '''
    # 池の中で一番高い所
    max_in_pond = 0
    for w in range(L, R+1):
        for h in range(B, T+1):
            max_in_pond = max(max_in_pond, garden[h][w])
    # 周りの壁の一番低い所
    min_wall = float('inf')
    for w in range(L-1, R+2):
        min_wall = min(min_wall, garden[B-1][w], garden[T+1][w])
    for h in range(B-1, T+2):
        min_wall = min(min_wall, garden[h][L-1], garden[h][R+1])

    if min_wall <= max_in_pond:
        return -1
    else:
        return calcVolume(L, R, T, B, min_wall)


while True:
    d, w = map(int, input().split())
    if d == 0:
        break
    garden = [list(map(int, input().split())) for _ in range(d)]
    ans = 0
    wallMin = 0
    # 池の範囲を全探索
    for L in range(1, w-1):
        for B in range(1, d-1):
            for R in range(L, w-1):
                for T in range(B, d-1):
                    ans = max(ans, pondsVolume(L, R, T, B))
    print(ans)

Python: while True:
    d, w = map(int, input().split())
    if d == 0:
        break
    area = []
    for _ in range(d):
        area.append(list(map(int, input().split())))
    v = 0
    for dp in range(1, d - 1):
        for wp in range(1, w - 1):
            for i in range(1, d - dp):
                for j in range(1, w - wp):
                    mawari = min(area[i - 1][j - 1:j + wp + 1] + area[i + dp][j - 1:j + wp + 1])
                    naka = 0
                    for ii in range(dp):
                        mawari = min(mawari, area[i + ii][j - 1], area[i + ii][j + wp])
                        naka = max([naka] + area[i + ii][j:j + wp])
                    if mawari > naka:
                        vn = 0
                        for ii in range(dp):
                            for jj in range(wp):
                                vn += mawari - area[i + ii][j + jj]
                        v = max(vn, v)
    print(v)

Python: while True:
    d, w = map(int, input().split())
    if d==w==0:
        break
    E=[list(map(int, input().split())) for i in range(d)]
    a=0
    for x2 in range(d):
        for y2 in range(w):
            for x1 in range(x2-1):
                for y1 in range(y2-1):
                    co=10**18
                    for x in range(x1, x2+1):
                        co=min(co, E[x][y1], E[x][y2])
                    for y in range(y1, y2+1):
                        co=min(co, E[x1][y], E[x2][y])
                    ci=cnt=0
                    for x in range(x1+1, x2):
                        for y in range(y1+1, y2):
                            ci=max(ci, E[x][y])
                            cnt+=E[x][y]
                    if ci < co:
                        a=max(ans, (x2-x1-1)*(y2-y1-1)*co - cnt)
    print(a)

Python: import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2,gcd
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():

    ans=[]
    
    while 1:
        d,w = MAP()

        if d==0 and w == 0:
            break
        else:
            lis=[]

            e=[LIST() for _ in range(d) ]

            #print(d,w)

            for x in combinations(range(d),2):
                for y in combinations(range(w),2):
                    if x[1]-x[0]!=1 and y[1]-y[0]!=1:

                        waku_min=9
                        naka_max=0
                        a=0
                        for p in range(x[0],x[1]+1):
                            for q in range(y[0],y[1]+1):
                                if p == x[0] or p == x[1] or q == y[0] or q == y[1] :
                                    waku_min=min(waku_min,e[p][q])
                                else:
                                    naka_max=max(naka_max,e[p][q])

                        if waku_min > naka_max:
                            #print('tate:',x)
                            #print('yoko:',y)
                            #print(waku_min,naka_max)
                            for p in range(x[0]+1,x[1]):
                                for q in range(y[0]+1,y[1]):
                                    a += waku_min-e[p][q]

                            lis.append(a)

            if not lis:
                ans.append(0)
            else:
                ans.append(max(lis))

        #print('lis:' ,lis)

    for x in ans:
        print(x)




if __name__ == '__main__':
    main()