#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
int dp[1010][1010];
string s[1010];
int main(){FIN;
int n,m,ans=0; cin>>n>>m;
fore(i,0,n) cin>>s[i];
fore(i,0,n) fore(j,0,m){
bool up=i&&j&&s[i-1][j]==s[i-1][j-1];
bool dw=j&&s[i][j-1]==s[i][j];
if(up&&dw) dp[i][j]=min({dp[i-1][j],dp[i][j-1],dp[i-1][j-1]})+1;
else dp[i][j]=1;
ans=max(ans,dp[i][j]);
}
cout << ans*ans << "\n";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZnN0IGZpcnN0CiNkZWZpbmUgc25kIHNlY29uZAojZGVmaW5lIGZvcmUoaSxhLGIpIGZvcihpbnQgaT1hLFRoeERlbT1iO2k8VGh4RGVtOysraSkKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBBTEwocykgcy5iZWdpbigpLHMuZW5kKCkKI2RlZmluZSBGSU4gaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTtjaW4udGllKDApO2NvdXQudGllKDApCiNkZWZpbmUgU1oocykgaW50KHMuc2l6ZSgpKQp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKdHlwZWRlZiBwYWlyPGludCxpbnQ+IGlpOwoKaW50IGRwWzEwMTBdWzEwMTBdOwpzdHJpbmcgc1sxMDEwXTsKCmludCBtYWluKCl7RklOOwoJaW50IG4sbSxhbnM9MDsgY2luPj5uPj5tOwoJZm9yZShpLDAsbikgY2luPj5zW2ldOwoJZm9yZShpLDAsbikgZm9yZShqLDAsbSl7CgkJYm9vbCB1cD1pJiZqJiZzW2ktMV1bal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