loop do
    d, w = gets.split.map(&:to_i)
    break if d == 0
    a = (1..d).map {gets.split.map(&:to_i)}
    max = 0
    (0..d-1).to_a.combination(2) do |y1, y2|
        next if y1 >= y2 - 1
        (0..w-1).to_a.combination(2) do |x1, x2|
            next if x1 >= x2 - 1
            h1 = (a[y1][x1..x2] + a[y2][x1..x2] + a[y1..y2].map{|r| r[x1]} + a[y1..y2].map{|r| r[x2]}).min
            h2 = 0
            v = h1 * (y2 - y1 - 1) * (x2 - x1 - 1)
            (y1+1..y2-1).each do |y|
                (x1+1..x2-1).each do |x|
                    h2 = a[y][x] if a[y][x] > h2
                    v -= a[y][x]
                end
            end
            next if h2 >= h1
            max = v if v > max
        end
    end
    p max
end

