#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
#define ll long long 
const int maxn = 1400 + 5;

int h, w;
int mem[maxn][maxn];
int dp[maxn][maxn];
int Max;

int solve()
{
    rep(i,w) if(mem[0][i] != 1) dp[0][i] = 1;
    rep(i,h) if(mem[i][0] != 1) dp[i][0] = 1;

    for(int i = 1; i < h; i++)
        for(int j = 1; j < w; j++){
            if(mem[i][j] == 1) dp[i][j] = 0;
            else{
                dp[i][j] = min(dp[i][j-1], min(dp[i-1][j-1], dp[i-1][j])) + 1;
                Max = max(Max, dp[i][j]);
            }
        }

    return Max*Max;
}

int main()
{
    cin >> h >> w;
    rep(i,h)
    rep(j,w){
        cin >> mem[i][j];
        if(!mem[i][j]) Max = 1;
    }
    cout << solve() << endl;
}
