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: from itertools import product
while True:
    d, w = map(int, input().split())  # 高さdと幅w
    if d == 0:
        break
    gridgraph = [list(map(int, input().split())) for _ in range(d)]
    ans = 0
    for si, sj in product(range(1, d-1), range(1, w-1)):
        for ti, tj in product(range(si, d-1), range(sj, w-1)):
            # これで内部の池の範囲が指定できた
            # 内部の最大値を考えたい
            max_in_area = 0
            for i, j in product(range(si, ti+1), range(sj, tj+1)):
                max_in_area = max(max_in_area, gridgraph[i][j])

            # 周囲の最小値を考えたい
            huti_min = 100
            # 右方向を考えたい
            for i, j in product([si-1, ti+1], range(sj-1, tj+2)):  # rangeの仕様に注意
                huti_min = min(huti_min, gridgraph[i][j])

            # 下方向を考えたい
            for i, j in product(range(si-1, ti+2), [sj-1, tj+1]):  # rangeの仕様に注意
                huti_min = min(huti_min, gridgraph[i][j])

            if max_in_area >= huti_min:
                continue

            tmp = 0
            for i, j in product(range(si, ti+1), range(sj, tj+1)):
                tmp += huti_min - gridgraph[i][j]
            ans = max(ans, tmp)

    print(ans)

Python: #2005_c
"""
n = int(input())
k = list("mcxi")
for i in range(n):
    d = {"m":0,"c":0,"x":0,"i":0}
    a,b  = input().split()
    a = list(a)
    b = list(b)
    a.insert(0,1)
    b.insert(0,1)
    for j in range(1,len(a)):
        if a[j] in k:
            if a[j-1] in k:
                d[a[j]] += 1
            else:
                d[a[j]] += int(a[j-1])
    for j in range(1,len(b))[::-1]:
        if b[j] in k:
            if b[j-1] in k:
                d[b[j]] += 1
            else:
                d[b[j]] += int(b[j-1])
            if d[b[j]] >= 10:
                l = b[j]
                while d[l] >= 10:
                    d[l] -= 10
                    l = k[k.index(l)-1]
                    d[l] += 1
    for j in k:
        if d[j]:
            if d[j] == 1:
                print(j,end = "")
            else:
                print(str(d[j])+j,end = "")
    print()
"""
#2017_c
while 1:
    h, w = map(int, input().split())
    if h == w == 0:
        break
    s = [list(map(int, input().split())) for i in range(h)]

    ans = 0
    for u in range(h):
        for d in range(u+2,h):
            for l in range(w):
                for r in range(l+2,w):
                    m = float("inf")
                    for i in range(u,d+1):
                        m = min(m,s[i][l],s[i][r])
                    for i in range(l,r+1):
                        m = min(m,s[u][i],s[d][i])
                    f = 1
                    su = 0
                    for i in range(u+1,d):
                        for j in range(l+1,r):
                            su += (m-s[i][j])
                            if s[i][j] >= m:
                                f = 0
                                break
                        if not f:
                            break
                    if f:
                        ans = max(ans,su)
    print(ans)

Python: def area(x_s,x_e,y_s,y_e):
	return int((x_e-x_s-1)*(y_e-y_s-1))

def minimum_border(A,x_s,x_e,y_s,y_e):
	min=A[x_s][y_s]
	for i in range(x_s,x_e+1):
		for j in range(y_s,y_e+1):
			if A[i][j]<min:
				min=A[i][j]
	return min

def maximum_inter(A,x_s,x_e,y_s,y_e):
	max=A[x_s+1][y_s+1]
	for i in range(x_s+1,x_e):
		for j in range(y_s+1,y_e):
			if A[i][j]>max:
				max=A[i][j]
	return max

A=[[0 for i in range(10)]for j in range(10)]
ans=[]

while True:
	n,m=map(int,input().split())

	if n==m==0:
		break
	for i in range(n):
		tmp=[]
		tmp=list(map(int,input().split()))
		tmp.reverse()
		for j in range(m):
			A[i][j]=tmp.pop()

	flag=0
	max_s=0
	for y_s in range(m-2):
		for y_e in range(m-3,m):
			for x_s in range(n-2):
				for x_e in range(n-3,n):
					if y_e-y_s<2 or x_e-x_s<2:
						pass
					else:
						#print(area(x_s,x_e,y_s,y_e))
						if minimum_border(A,x_s,x_e,y_s,y_e)>maximum_inter(A,x_s,x_e,y_s,y_e):
							if flag==0:	
								print("=====")
								max_s=area(x_s,x_e,y_s,y_e)
							else:
								if area(x_s,x_e,y_s,y_e)>max_s:
									max_s=area(x_s,x_e,y_s,y_e)
							ans.append(max_s)

ans.reverse()
for i in range(len(ans)):
	print(ans.pop())