#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
// Kiểm tra hình vuông kích thước size tại vị trí (x, y)
bool isSquare(const vector<vector<int>>& mat, int x, int y, int size, int value) {
for (int i = x; i < x + size; ++i) {
for (int j = y; j < y + size; ++j) {
if (mat[i][j] != value) return false;
}
}
return true;
}
int main() {
int m, n;
cin >> m >> n;
vector<vector<int>> mat(m, vector<int>(n));
// Nhập ma trận
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
cin >> mat[i][j];
}
}
int maxSize = 0;
// Kiểm tra từng ô (brute force)
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
for (int size = 1; i + size <= m && j + size <= n; ++size) {
if (isSquare(mat, i, j, size, mat[i][j])) {
maxSize = max(maxSize, size);
} else {
break;
}
}
}
}
cout << maxSize * maxSize << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIEtp4buDbSB0cmEgaMOsbmggdnXDtG5nIGvDrWNoIHRoxrDhu5tjIHNpemUgdOG6oWkgduG7iyB0csOtICh4LCB5KQpib29sIGlzU3F1YXJlKGNvbnN0IHZlY3Rvcjx2ZWN0b3I8aW50Pj4mIG1hdCwgaW50IHgsIGludCB5LCBpbnQgc2l6ZSwgaW50IHZhbHVlKSB7CiAgICBmb3IgKGludCBpID0geDsgaSA8IHggKyBzaXplOyArK2kpIHsKICAgICAgICBmb3IgKGludCBqID0geTsgaiA8IHkgKyBzaXplOyArK2opIHsKICAgICAgICAgICAgaWYgKG1hdFtpXVtqXSAhPSB2YWx1ZSkgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgIH0KICAgIHJldHVybiB0cnVlOwp9CgppbnQgbWFpbigpIHsKICAgIGludCBtLCBuOwogICAgY2luID4+IG0gPj4gbjsKCiAgICB2ZWN0b3I8dmVjdG9yPGludD4+IG1hdChtLCB2ZWN0b3I8aW50PihuKSk7CgogICAgLy8gTmjhuq1wIG1hIHRy4bqtbgogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyArK2kpIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IG47ICsraikgewogICAgICAgICAgICBjaW4gPj4gbWF0W2ldW2pdOwogICAgICAgIH0KICAgIH0KCiAgICBpbnQgbWF4U2l6ZSA9IDA7CgogICAgLy8gS2nhu4NtIHRyYSB04burbmcgw7QgKGJydXRlIGZvcmNlKQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyArK2kpIHsKICAgICAgICBmb3IgKGludCBqID0gMDsgaiA8IG47ICsraikgewogICAgICAgICAgICBmb3IgKGludCBzaXplID0gMTsgaSArIHNpemUgPD0gbSAmJiBqICsgc2l6ZSA8PSBuOyArK3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChpc1NxdWFyZShtYXQsIGksIGosIHNpemUsIG1hdFtpXVtqXSkpIHsKICAgICAgICAgICAgICAgICAgICBtYXhTaXplID0gbWF4KG1heFNpemUsIHNpemUpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBjb3V0IDw8IG1heFNpemUgKiBtYXhTaXplIDw8IGVuZGw7CgogICAgcmV0dXJuIDA7Cn0=