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: while True:
    d, w = map(int, input().split())
    if d == 0 and w == 0:
        break

    e = [list(map(int, input().split())) for i in range(d)]
    V = 0
    for i_l in range(d - 2):
        for i_r in range(min(i_l + 2, d), d):
            for j_l in range(w - 2):
                for j_r in range(min(j_l + 2, w), w):
                    min_out = 10 ** 10
                    max_in = 0
                    tmp = 0
                    for i in range(i_l, i_r + 1):
                        for j in range(j_l, j_r + 1):
                            if i == i_l or i == i_r or j == j_l or j == j_r:
                                #print(i, j)
                                min_out = min(min_out, e[i][j])
                            else:
                                max_in = max(max_in, e[i][j])

                    for i in range(i_l, i_r + 1):
                        for j in range(j_l, j_r + 1):
                            if min_out > max_in:
                                if i == i_l or i == i_r or j == j_r or j == j_l:
                                    1
                                else:
                                    #print(i_l, i_r, j_l, j_r, i, j, min_out, max_in, e[i][j])
                                    tmp += min_out - e[i][j]


                    #print(tmp)
                    V = max(tmp, V)

    print(V)

Python: while 1:
    d, w = map(int, input().split())
    if d == w == 0:
        break
    E = [list(map(int, input().split())) for i in range(d)]
    ans = 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:
                        ans = max(ans, (x2-x1-1)*(y2-y1-1)*co - cnt)
    print(ans)

Python: while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    E = [list(map(int, input().split())) for i in range(n)]
    ans=0
    for x in range(n-2):
        for y in range(m-2):
            for w in range(3,n-x+1):
                
                for h in range(3,m-y+1):
                    N=0
                    A=E[x][y]
                    B=0
                    for i in range(w):
                        for j in range(h):
                            if i==0 or j==0 or j==h-1 or i==w-1:
                                A=min(A,E[x+i][y+j])
                            else:
                                B=max(B,E[x+i][y+j])

                    if A>B:
                        for i in range(w):
                            for j in range(h):
                                if i!=0 and j!=0 and j!=h-1 and i!=w-1:
                                    N=N+A-E[x+i][y+j]
                                    
                    ans=max(ans,N)

    print(ans)

Python: def f(l,r,u,d):
    global e,no
    res = 0
    hori = 10
    for i in range(u,d+1):
        if i==u or i==d:
            hori = min(hori,min(e[i][l:r+1]))
        else:
            hori = min(hori,e[i][l],e[i][r])
    if hori==no:
        return 0
    for i in range(u+1,d):
        for j in range(l+1,r):
            if hori<=e[i][j]:
                return 0
            res += abs(hori-e[i][j])
    return res
while True:
    D,W = map(int,input().split())
    if D+W==0:
        break
    e = [list(map(int,input().split())) for _ in range(D)]
    for i in range(D):
        no = min(e[0]) if i==0 else min(no,min(e[i]))
    #l,r,u,d
    ans = 0
    for l in range(W-2):
        for r in range(l+2,W):
            for u in range(D-2):
                for d in range(u+2,D):
                    ans = max(ans,f(l,r,u,d))
    print(ans)