#include <bits/stdc++.h>
using namespace std;
int H,W;
int S[1405][1405];

int mini(int a,int b,int c){
    if(a<=b){
        if(a<=c) return a;
        else{
            return c;
        }
    }

    else{
        if(b>=c) return c;
        else return b;
    }
}

int main(){
    scanf("%d %d",&H,&W);
    int value, maxSpace = 0;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            scanf("%d",&value);
            if(value==0){
                S[i][j] = 1;
                maxSpace = 1;
            }
            else S[i][j] = 0;
        }
    }
    for(int i=1;i<H;++i){
        for(int j=1;j<W;++j){
            if(S[i][j]!=0){
                S[i][j] = mini(S[i-1][j-1],S[i-1][j],S[i][j-1])+1;
                if(S[i][j]>maxSpace) maxSpace = S[i][j];
            }
        }
    }

    printf("%d\n",maxSpace*maxSpace);
}

