#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
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];
}
}
vector<vector<int>> dp(m, vector<int>(n, 0));
int maxSide = 0;
// Tính toán dp
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (i == 0 || j == 0) {
dp[i][j] = mat[i][j];
} else if (mat[i][j] == mat[i-1][j] && mat[i][j] == mat[i][j-1] && mat[i][j] == mat[i-1][j-1]) {
dp[i][j] = min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]}) + 1;
} else {
dp[i][j] = mat[i][j];
}
maxSide = max(maxSide, dp[i][j]);
}
}
cout << maxSide * maxSide << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IG0sIG47CiAgICBjaW4gPj4gbSA+PiBuOwoKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gbWF0KG0sIHZlY3RvcjxpbnQ+KG4pKTsKCiAgICAvLyBOaOG6rXAgbWEgdHLhuq1uCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG07ICsraSkgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbjsgKytqKSB7CiAgICAgICAgICAgIGNpbiA+PiBtYXRbaV1bal07CiAgICAgICAgfQogICAgfQoKICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4gZHAobSwgdmVjdG9yPGludD4obiwgMCkpOwogICAgaW50IG1heFNpZGUgPSAwOwoKICAgIC8vIFTDrW5oIHRvw6FuIGRwCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG07ICsraSkgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbjsgKytqKSB7CiAgICAgICAgICAgIGlmIChpID09IDAgfHwgaiA9PSAwKSB7CiAgICAgICAgICAgICAgICBkcFtpXVtqXSA9IG1hdFtpXVtqXTsKICAgICAgICAgICAgfSBlbHNlIGlmIChtYXRbaV1bal0gPT0gbWF0W2ktMV1bal0gJiYgbWF0W2ldW2pdID09IG1hdFtpXVtqLTFdICYmIG1hdFtpXVtqXSA9PSBtYXRbaS0xXVtqLTFdKSB7CiAgICAgICAgICAgICAgICBkcFtpXVtqXSA9IG1pbih7ZHBbaS0xXVtqXSwgZHBbaV1bai0xXSwgZHBbaS0xXVtqLTFdfSkgKyAxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZHBbaV1bal0gPSBtYXRbaV1bal07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbWF4U2lkZSA9IG1heChtYXhTaWRlLCBkcFtpXVtqXSk7CiAgICAgICAgfQogICAgfQoKICAgIGNvdXQgPDwgbWF4U2lkZSAqIG1heFNpZGUgPDwgZW5kbDsKCiAgICByZXR1cm4gMDsKfQ==