#include<stdio.h>
int main(void) {
	int i, j, d, w, e[10][10], ds, ws, dl, wl, x, y, min, max, total, res;
	while (1) {
		res = 0;
		scanf("%d", &d);
		scanf("%d", &w);
		if ((d == 0) && (w == 0)) {
			break;
		}
		for (i = 0; i < d; i++) {
			for (j = 0; j < w; j++) {
				scanf("%d", &e[i][j]);
			}
		}
		for (ds = 0; ds < d - 2; ds++) {
			for (ws = 0; ws < w - 2; ws++) {
			//	printf("ds:%d ws:%d\n", ds, ws);
				for (dl = 2 + ds; dl < d; dl++) {
					for (wl = 2 + ws; wl < w; wl++) {
					//	printf("dl:%d wl:%d\n", dl, wl);
						min = 10;
						max = 0;
						total = 0;
						for (x = ds; x <= dl; x++) {
						//	printf("%d %d\n", e[x][ws],e[x][wl]);
							if (min > e[x][ws]) {
								min = e[x][ws];
							}
							if (min > e[x][wl]) {
								min = e[x][wl];
							}
						//	printf("min:%d\n", min);
						}
						for (y = ws; y <= wl; y++) {
						//	printf("%d %d\n", e[ds][y], e[dl][y]);
							if (min > e[ds][y]) {
								min = e[ds][y];
							}
							if (min > e[dl][y]) {
								min = e[dl][y];
							}
						//	printf("min:%d\n", min);
						}
						for (x = ds + 1; x < dl; x++) {
							for (y = ws + 1; y < wl; y++) {
								if (max<e[x][y]) {
									max = e[x][y];
								}
								total += min - e[x][y];
							}
						}
						if (max >= min) {
							total = 0;
						}
						if (res < total) {
							res = total;
						}
						//printf("finish\n");
						//printf("res:%d total:%d\n", res, total);
					}
				}
			}
		}
		printf("%d\n", res);
	}
	return 0;
}
