// author : daohuyenchi
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define db double
#define i32 int32_t
#define i64 int64_t
#define ll long long
//
#define fi first
#define se second
// #define int long long // consider carefully
//
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define pil pair<int, ll>
#define PAIR make_pair
// TIME IS LIMITED ...
#define rep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define repd(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define repv(v, H) for(auto &v: H)
// REFLECT ON THE PAST ...
#define RESET(c, x) memset(c, x, sizeof(c))
#define MASK(i) (1LL << (i))
#define BIT(mask, i) (((mask) >> (i)) & 1LL)
#define ONBIT(mask, i) ((mask) | (1LL << (i)))
#define OFFBIT(mask, i) ((mask) &~ (1LL << (i)))
#define COUNTBIT __builtin_popcountll
// 30 / 1 / 2024 ? love is zero... start from zero
#define PB push_back
#define EB emplace_back
#define vi vector<int>
#define vll vector<ll>
#define lwb lower_bound
#define upb upper_bound
#define all(v) (v).begin(), (v).end()
#define special(H) (H).resize(distance(H.begin(), unique(all(H))))
//
#define sp ' '
#define nl '\n'
#define yes "YES"
#define no "NO"
#define Log2(n) (63 - __builtin_clzll(n))
#define left __left__
#define right __right__
//____________________________________________________________________
template <class X, class Y> bool maximize(X &a, const Y &b) {
if(a < b) return a = b, true;
return false;
}
template <class X, class Y> bool minimize(X &a, const Y &b) {
if(a > b) return a = b, true;
return false;
}
const int MOD = 1000000007;
// const int MOD[2] = {1000000009, 998244353};
template<class X> void modmize(X &x, int cur_Mod = MOD) {
if(x >= cur_Mod) x -= cur_Mod;
if(x < 0) x += cur_Mod;
}
template <class... T>
void print(T&&... n) {
using exp = int[];
exp{0, (cerr << n << sp, 0)...};
cerr << endl;
}
template <class T, class... C>
void assign(int n, T v, C&&... a) {
using e = int[];
e{(a.assign(n, v), 0)...};
}
template <class... C>
void resize(int n, C&&... a) {
using e = int[];
e{(a.resize(n), 0)...};
}
template <class T>
using vector2d = vector<vector<T>>;
template <class T>
using vector3d = vector<vector2d<T>>;
template <class T> int ssize(T &a) { return (int) a.size(); }
//____________________________________________________________________
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
const long long oo = 1e18 + 7;
const int INF = 2e9;
const int nmax = 2e5 + 10;
const int MAX = 2e5;
const int base = 311;
const db eps = 1e-6;
const int block = 500;
static const double PI = acos(-1.0);
//____________________________________________________________________
int n, m;
vector2d<int> a;
vector2d<int> fd, fu, fl, fr;
namespace subtask1 {
struct HuyenChi {
vector<int> st;
void Init(int _n) {
assign(_n * 4 + 5, INF, st);
}
void upd(int id, int l, int r, int i, int val) {
if(l > i || r < i) return;
if(l == r) {
minimize(st[id], val);
return;
}
int mid = (l + r) / 2;
upd(id * 2, l, mid, i, val);
upd(id * 2 + 1, mid + 1, r, i, val);
st[id] = min(st[id * 2], st[id * 2 + 1]);
}
int walk(int id, int l, int r, int val) {
if(l == r) return (st[id] <= val ? l : INF);
int mid = (l + r) / 2;
if(st[id * 2 + 1] <= val) return walk(id * 2 + 1, mid + 1, r, val);
return walk(id * 2, l, mid, val);
}
int calc(int id, int l, int r, int u, int v, int val) {
if(l > v || r < u || st[id] > val) return INF;
if(u <= l && r <= v) {
if(st[id] <= val) return walk(id, l, r, val);
else return INF;
}
int mid = (l + r) >> 1;
if(v <= mid) return calc(id * 2, l, mid, u, v, val);
else if(u > mid) return calc(id * 2 + 1, mid + 1, r, u, v, val);
int cur = calc(id * 2 + 1, mid + 1, r, u, v, val);
if(cur < INF) return cur;
return calc(id * 2, l, mid, u, v, val);
}
} ;
void SOLVE() {
HuyenChi chi;
vector2d<pii> List(2 * m + 1, vector<pii>());
rep(i, 1, n) {
rep(j, 1, m) {
if(a[i][j] == 0) continue;
List[i - j + m].push_back({i, j});
}
}
int ans = 0;
rep(_i, 0, m + m) {
if(List[_i].empty() == 0) {
chi.Init(n);
auto &g = List[_i];
sort(all(List[_i]));
repd(i, ssize(g) - 1, 0) {
int x = g[i].fi;
int y = g[i].se;
if(a[x][y] == 0) continue;
int v2 = min(fl[x][y], fu[x][y]);
chi.upd(1, 1, n, x, x - v2);
int v = min(fr[x][y], fd[x][y]);
int x2 = chi.calc(1, 1, n, x, x + v - 1, x - 1);
if(x2 != INF) {
maximize(ans, x2 - x + 1);
}
}
}
}
cout << 1ll * ans * ans << nl;
}
}
int rnd(int l, int r) {
return uniform_int_distribution<int> (l, r) (rng);
}
void tintingyn() {
cin >> n >> m;
// n = 1e3; m = 1e3;
assign(n + 2, vector<int>(m + 2, 0), a);
rep(i, 1, n) {
rep(j, 1, m) {
cin >> a[i][j];
// a[i][j] = rnd(0, 1);
}
}
assign(n + 2, vector<int>(m + 2, 0), fd, fu, fl, fr);
rep(i, 1, n) {
fl[i][1] = 1;
rep(j, 2, m) {
if(a[i][j] != a[i][j - 1]) fl[i][j] = 1;
else fl[i][j] = fl[i][j - 1] + 1;
}
fr[i][m] = 1;
repd(j, m - 1, 1) {
if(a[i][j] != a[i][j + 1]) fr[i][j] = 1;
else fr[i][j] = fr[i][j + 1] + 1;
}
}
rep(j, 1, m) {
fu[1][j] = 1;
rep(i, 2, n) {
if(a[i][j] != a[i - 1][j]) fu[i][j] = 1;
else fu[i][j] = fu[i - 1][j] + 1;
}
fd[n][j] = 1;
repd(i, n - 1, 1) {
if(a[i][j] != a[i + 1][j]) fd[i][j] = 1;
else fd[i][j] = fd[i + 1][j] + 1;
}
}
subtask1:: SOLVE();
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//________________________________________________________________
#define TASK "MSQUARE"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
//________________________________________________________________
// CODE FROM HERE ...!
int num_test = 1;
// cin >> num_test;
while(num_test--) {
tintingyn();
}
cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" << nl;
return 0;
}
CgovLyBhdXRob3IgOiBkYW9odXllbmNoaQoKCgojaW5j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bmUgT05CSVQobWFzaywgaSkgKChtYXNrKSB8ICgxTEwgPDwgKGkpKSkKI2RlZmluZSBPRkZCSVQobWFzaywgaSkgKChtYXNrKSAmfiAoMUxMIDw8IChpKSkpCiNkZWZpbmUgQ09VTlRCSVQgX19idWlsdGluX3BvcGNvdW50bGwKLy8gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDMwIC8gMSAvIDIwMjQgPyBsb3ZlIGlzIHplcm8uLi4gc3RhcnQgZnJvbSB6ZXJvIAojZGVmaW5lIFBCIHB1c2hfYmFjawojZGVmaW5lIEVCIGVtcGxhY2VfYmFjawojZGVmaW5lIHZpIHZlY3RvcjxpbnQ+CiNkZWZpbmUgdmxsIHZlY3RvcjxsbD4KI2RlZmluZSBsd2IgbG93ZXJfYm91bmQKI2RlZmluZSB1cGIgdXBwZXJfYm91bmQKI2RlZmluZSBhbGwodikgKHYpLmJlZ2luKCksICh2KS5lbmQoKQojZGVmaW5lIHNwZWNpYWwoSCkgKEgpLnJlc2l6ZShkaXN0YW5jZShILmJlZ2luKCksIHVuaXF1ZShhbGwoSCkpKSkKLy8gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAojZGVmaW5lIHNwICcgJyAKI2RlZmluZSBubCAnXG4nCiNkZWZpbmUgeWVzICJZRVMiCiNkZWZpbmUgbm8gIk5PIgojZGVmaW5lIExvZzIobikgKDYzIC0gX19idWlsdGluX2NsemxsKG4pKQojZGVmaW5lIGxlZnQgX19sZWZ0X18KI2RlZmluZSByaWdodCBfX3JpZ2h0X18gCgovL19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCgoKdGVtcGxhdGUgPGNsYXNzIFgsIGNsYXNzIFk+IGJvb2wgbWF4aW1pemUoWCAmYSwgY29uc3QgWSAmYikgewogICAgaWYoYSA8IGIpIHJldHVybiBhID0gYiwgdHJ1ZTsKICAgIHJldHVybiBmYWxzZTsKf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W50IHNzaXplKFQgJmEpIHsgcmV0dXJuIChpbnQpIGEuc2l6ZSgpOyB9CgoKLy9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwoKCm10MTk5Mzcgcm5nKGNocm9ubzo6c3RlYWR5X2Nsb2NrKCkubm93KCkudGltZV9zaW5jZV9lcG9jaCgpLmNvdW50KCkpOwoKY29uc3QgbG9uZyBsb25nIG9vID0gMWUxOCArIDc7CmNvbnN0IGludCBJTkYgICAgICA9IDJlOTsKY29uc3QgaW50IG5tYXggICAgID0gMmU1ICsgMTA7CmNvbnN0IGludCBNQVggICAgICA9IDJlNTsKY29uc3QgaW50IGJhc2UgICAgID0gMzExOwpjb25zdCBkYiBlcHMgICAgICAgPSAxZS02Owpjb25zdCBpbnQgYmxvY2sgICAgPSA1MDA7CnN0YXRpYyBjb25zdCBkb3VibGUgUEkgPSBhY29zKC0xLjApOwoKLy9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwoKCmludCBuLCBtOwp2ZWN0b3IyZDxpbnQ+IGE7CnZlY3RvcjJkPGludD4gZmQsIGZ1LCBmbCwgZnI7CgpuYW1lc3BhY2Ugc3VidGFzazEgewoKICAgIHN0cnVjdCBIdXllbkNoaSB7CgogICAgICAgIHZlY3RvcjxpbnQ+IHN0OwoKICAgICAgICB2b2lkIEluaXQoaW50IF9uKSB7CiAgICAgICAgICAgIGFzc2lnbihfbiAqIDQgKyA1LCBJTkYsIHN0KTsKICAgICAgICB9CgogICAgICAgIHZvaWQgdXBkKGludCBpZCwgaW50IGwsIGludCByLCBpbnQgaSwgaW50IHZhbCkgewogICAgICAgICAgICBpZihsID4gaSB8fCByIDwgaSkgcmV0dXJuOwogICAgICAgICAgICBpZihsID09IHIpIHsKICAgICAgICAgICAgICAgIG1pbmltaXplKHN0W2lkXSwgdmFsKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbnQgbWlkID0gKGwgKyByKSAvIDI7CiAgICAgICAgICAgIHVwZChpZCAqIDIsIGwsIG1pZCwgaSwgdmFsKTsKICAgICAgICAgICAgdXBkKGlkICogMiArIDEsIG1pZCArIDEsIHIsIGksIHZhbCk7CiAgICAgICAgICAgIHN0W2lkXSA9IG1pbihzdFtpZCAqIDJdLCBzdFtpZCAqIDIgKyAxXSk7CiAgICAgICAgfQoKICAgICAgICBpbnQgd2FsayhpbnQgaWQsIGludCBsLCBpbnQgciwgaW50IHZhbCkgewogICAgICAgICAgICBpZihsID09IHIpIHJldHVybiAoc3RbaWRdIDw9IHZhbCA/IGwgOiBJTkYpOwogICAgICAgICAgICBpbnQgbWlkID0gKGwgKyByKSAvIDI7CiAgICAgICAgICAgIGlmKHN0W2lkICogMiArIDFdIDw9IHZhbCkgcmV0dXJuIHdhbGsoaWQgKiAyICsgMSwgbWlkICsgMSwgciwgdmFsKTsKICAgICAgICAgICAgcmV0dXJuIHdhbGsoaWQgKiAyLCBsLCBtaWQsIHZhbCk7CiAgICAgICAgfQoKICAgICAgICBpbnQgY2FsYyhpbnQgaWQsIGludCBsLCBpbnQgciwgaW50IHUsIGludCB2LCBpbnQgdmFsKSB7CiAgICAgICAgICAgIGlmKGwgPiB2IHx8IHIgPCB1IHx8IHN0W2lkXSA+IHZhbCkgcmV0dXJuIElORjsKICAgICAgICAgICAgaWYodSA8PSBsICYmIHIgPD0gdikgewogICAgICAgICAgICAgICAgaWYoc3RbaWRdIDw9IHZhbCkgcmV0dXJuIHdhbGsoaWQsIGwsIHIsIHZhbCk7CiAgICAgICAgICAgICAgICBlbHNlIHJldHVybiBJTkY7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKICAgICAgICAgICAgaWYodiA8PSBtaWQpIHJldHVybiBjYWxjKGlkICogMiwgbCwgbWlkLCB1LCB2LCB2YWwpOwogICAgICAgICAgICBlbHNlIGlmKHUgPiBtaWQpIHJldHVybiBjYWxjKGlkICogMiArIDEsIG1pZCArIDEsIHIsIHUsIHYsIHZhbCk7CiAgICAgICAgICAgIGludCBjdXIgPSBjYWxjKGlkICogMiArIDEsIG1pZCArIDEsIHIsIHUsIHYsIHZhbCk7CiAgICAgICAgICAgIGlmKGN1ciA8IElORikgcmV0dXJuIGN1cjsKICAgICAgICAgICAgcmV0dXJuIGNhbGMoaWQgKiAyLCBsLCBtaWQsIHUsIHYsIHZhbCk7CiAgICAgICAgfSAKCiAgICB9IDsKCiAgICB2b2lkIFNPTFZFKCkgewoKICAgICAgICBIdXllbkNoaSBjaGk7CgogICAgICAgIHZlY3RvcjJkPHBpaT4gTGlzdCgyICogbSArIDEsIHZlY3RvcjxwaWk+KCkpOwoKICAgICAgICByZXAoaSwgMSwgbikgewogICAgICAgICAgICByZXAoaiwgMSwgbSkgewogICAgICAgICAgICAgICAgaWYoYVtpXVtqXSA9PSAwKSBjb250aW51ZTsKICAgICAgICAgICAgICAgIExpc3RbaSAtIGogKyBtXS5wdXNoX2JhY2soe2ksIGp9KTsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaW50IGFucyA9IDA7CiAgICAgICAgcmVwKF9pLCAwLCBtICsgbSkgewogICAgICAgICAgICBpZihMaXN0W19pXS5lbXB0eSgpID09IDApIHsKICAgICAgICAgICAgICAgIGNoaS5Jbml0KG4pOwoKICAgICAgICAgICAgICAgIGF1dG8gJmcgPSBMaXN0W19pXTsKICAgICAgICAgICAgICAgIHNvcnQoYWxsKExpc3RbX2ldKSk7CgogICAgICAgICAgICAgICAgcmVwZChpLCBzc2l6ZShnKSAtIDEsIDApIHsKICAgICAgICAgICAgICAgICAgICBpbnQgeCA9IGdbaV0uZmk7CiAgICAgICAgICAgICAgICAgICAgaW50IHkgPSBnW2ldLnNlOwogICAgICAgICAgICAgICAgICAgIGlmKGFbeF1beV0gPT0gMCkgY29udGludWU7CgogICAgICAgICAgICAgICAgICAgIGludCB2MiA9IG1pbihmbFt4XVt5XSwgZnVbeF1beV0pOwogICAgICAgICAgICAgICAgICAgIGNoaS51cGQoMSwgMSwgbiwgeCwgeCAtIHYyKTsKICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICBpbnQgdiA9IG1pbihmclt4XVt5XSwgZmRbeF1beV0pOwogICAgICAgICAgICAgICAgICAgIGludCB4MiA9IGNoaS5jYWxjKDEsIDEsIG4sIHgsIHggKyB2IC0gMSwgeCAtIDEpOwogICAgICAgICAgICAgICAgICAgIGlmKHgyICE9IElORikgewogICAgICAgICAgICAgICAgICAgICAgICBtYXhpbWl6ZShhbnMsIHgyIC0geCArIDEpOwoKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBjb3V0IDw8IDFsbCAqIGFucyAqIGFucyA8PCBubDsKCiAgICB9Cgp9CgppbnQgcm5kKGludCBsLCBpbnQgcikgewogICAgcmV0dXJuIHVuaWZvcm1faW50X2Rpc3RyaWJ1dGlvbjxpbnQ+IChsLCByKSAocm5nKTsKfQoKdm9pZCB0aW50aW5neW4oKSB7CgogICAgY2luID4+IG4gPj4gbTsKCiAgICAvLyBuID0gMWUzOyBtID0gMWUzOwoKICAgIGFzc2lnbihuICsgMiwgdmVjdG9yPGludD4obSArIDIsIDApLCBhKTsKICAgIHJlcChpLCAxLCBuKSB7CiAgICAgICAgcmVwKGosIDEsIG0pIHsKICAgICAgICAgICAgY2luID4+IGFbaV1bal07CiAgICAgICAgICAgIC8vIGFbaV1bal0gPSBybmQoMCwgMSk7CiAgICAgICAgfQogICAgfQoKICAgIGFzc2lnbihuICsgMiwgdmVjdG9yPGludD4obSArIDIsIDApLCBmZCwgZnUsIGZsLCBmcik7CgogICAgcmVwKGksIDEsIG4pIHsKICAgICAgICBmbFtpXVsxXSA9IDE7CiAgICAgICAgcmVwKGosIDIsIG0pIHsKICAgICAgICAgICAgaWYoYVtpXVtqXSAhPSBhW2ldW2ogLSAxXSkgZmxbaV1bal0gPSAxOwogICAgICAgICAgICBlbHNlIGZsW2ldW2pdID0gZmxbaV1baiAtIDFdICsgMTsKICAgICAgICB9CiAgICAgICAgZnJbaV1bbV0gPSAxOwogICAgICAgIHJlcGQoaiwgbSAtIDEsIDEpIHsKICAgICAgICAgICAgaWYoYVtpXVtqXSAhPSBhW2ldW2ogKyAxXSkgZnJbaV1bal0gPSAxOwogICAgICAgICAgICBlbHNlIGZyW2ldW2pdID0gZnJbaV1baiArIDFdICsgMTsKICAgICAgICB9CiAgICB9CgogICAgcmVwKGosIDEsIG0pIHsKICAgICAgICBmdVsxXVtqXSA9IDE7CiAgICAgICAgcmVwKGksIDIsIG4pIHsKICAgICAgICAgICAgaWYoYVtpXVtqXSAhPSBhW2kgLSAxXVtqXSkgZnVbaV1bal0gPSAxOwogICAgICAgICAgICBlbHNlIGZ1W2ldW2pdID0gZnVbaSAtIDFdW2pdICsgMTsKICAgICAgICB9CgogICAgICAgIGZkW25dW2pdID0gMTsKICAgICAgICByZXBkKGksIG4gLSAxLCAxKSB7CiAgICAgICAgICAgIGlmKGFbaV1bal0gIT0gYVtpICsgMV1bal0pIGZkW2ldW2pdID0gMTsKICAgICAgICAgICAgZWxzZSBmZFtpXVtqXSA9IGZkW2kgKyAxXVtqXSArIDE7CiAgICAgICAgfQogICAgfQoKICAgIHN1YnRhc2sxOjogU09MVkUoKTsKCgoKfQoKc2lnbmVkIG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGNvdXQudGllKDApOwoKICAgIC8vX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwoKICAgICNkZWZpbmUgVEFTSyAiTVNRVUFSRSIKICAgIGlmKGZvcGVuKFRBU0siLmlucCIsICJyIikpIHsKICAgICAgICBmcmVvcGVuKFRBU0siLmlucCIsICJyIiwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4oVEFTSyIub3V0IiwgInciLCBzdGRvdXQpOwogICAgfQoKICAgIC8vX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwogICAgCiAgICAvLyAgQ09ERSBGUk9NIEhFUkUgLi4uISAKCgoKCgogICAgaW50IG51bV90ZXN0ID0gMTsgCiAgICAvLyBjaW4gPj4gbnVtX3Rlc3Q7CgogICAgd2hpbGUobnVtX3Rlc3QtLSkgewoKICAgICAgICB0aW50aW5neW4oKTsKCiAgICB9CgoKICAgIGNlcnIgPDwgJ1xuJyA8PCAiVGltZSBlbGFwc2VkOiAiIDw8ICgxLjAgKiBjbG9jaygpIC8gQ0xPQ0tTX1BFUl9TRUMpIDw8ICIgc1xuIiA8PCBubDsKCiAgICByZXR1cm4gMDsKfQ==