#include <iostream>
#include <cstring>
using namespace std;
bool visited[25][25];
int m[25][25];
int M, N;
int maxScore = 0;
void calculateScore(int x, int y, int color) {
if (x < 0 || y < 0 || x >= M || y >= N || visited[x][y] || m[x][y] != color) {
return;
}
visited[x][y] = true;
maxScore++;
calculateScore(x+1, y, color);
calculateScore(x-1, y, color);
calculateScore(x, y+1, color);
calculateScore(x, y-1, color);
}
int main() {
memset(visited, false, sizeof(visited));
cin >> M >> N;
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
cin >> m[i][j];
}
}
int maxTotalScore = 0;
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
memset(visited, false, sizeof(visited));
maxScore = 0;
calculateScore(i, j, m[i][j]);
if (maxScore > 1) {
int score = maxScore * (maxScore - 1);
if (score > maxTotalScore) {
maxTotalScore = score;
}
}
}
}
cout << maxTotalScore << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmJvb2wgdmlzaXRlZFsyNV1bMjVdOwppbnQgbVsyNV1bMjVdOwppbnQgTSwgTjsKaW50IG1heFNjb3JlID0gMDsKCnZvaWQgY2FsY3VsYXRlU2NvcmUoaW50IHgsIGludCB5LCBpbnQgY29sb3IpIHsKICAgIGlmICh4IDwgMCB8fCB5IDwgMCB8fCB4ID49IE0gfHwgeSA+PSBOIHx8IHZpc2l0ZWRbeF1beV0gfHwgbVt4XVt5XSAhPSBjb2xvcikgewogICAgICAgIHJldHVybjsKICAgIH0KICAgIAogICAgdmlzaXRlZFt4XVt5XSA9IHRydWU7CiAgICBtYXhTY29yZSsrOwogICAgCiAgICBjYWxjdWxhdGVTY29yZSh4KzEsIHksIGNvbG9yKTsKICAgIGNhbGN1bGF0ZVNjb3JlKHgtMSwgeSwgY29sb3IpOwogICAgY2FsY3VsYXRlU2NvcmUoeCwgeSsxLCBjb2xvcik7CiAgICBjYWxjdWxhdGVTY29yZSh4LCB5LTEsIGNvbG9yKTsKfQoKaW50IG1haW4oKSB7CiAgICBtZW1zZXQodmlzaXRlZCwgZmFsc2UsIHNpemVvZih2aXNpdGVkKSk7CiAgICBjaW4gPj4gTSA+PiBOOwogICAgCiAgICBmb3IgKGludCBpID0gMDsgaSA8IE07IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgTjsgaisrKSB7CiAgICAgICAgICAgIGNpbiA+PiBtW2ldW2pdOwogICAgICAgIH0KICAgIH0KICAgIAogICAgaW50IG1heFRvdGFsU2NvcmUgPSAwOwogICAgCiAgICBmb3IgKGludCBpID0gMDsgaSA8IE07IGkrKykgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgTjsgaisrKSB7CiAgICAgICAgICAgIG1lbXNldCh2aXNpdGVkLCBmYWxzZSwgc2l6ZW9mKHZpc2l0ZWQpKTsKICAgICAgICAgICAgbWF4U2NvcmUgPSAwOwogICAgICAgICAgICBjYWxjdWxhdGVTY29yZShpLCBqLCBtW2ldW2pdKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmIChtYXhTY29yZSA+IDEpIHsKICAgICAgICAgICAgICAgIGludCBzY29yZSA9IG1heFNjb3JlICogKG1heFNjb3JlIC0gMSk7CiAgICAgICAgICAgICAgICBpZiAoc2NvcmUgPiBtYXhUb3RhbFNjb3JlKSB7CiAgICAgICAgICAgICAgICAgICAgbWF4VG90YWxTY29yZSA9IHNjb3JlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgCiAgICBjb3V0IDw8IG1heFRvdGFsU2NvcmUgPDwgZW5kbDsKICAgIAogICAgcmV0dXJuIDA7Cn0K