#include<stdio.h>
#include<algorithm>
using namespace std;
#define MAX 1401

int c[MAX][MAX], C[MAX][MAX], H, W;

void dp() {
    int Max = 0;

    for (int i=0; i<=H; i++) C[i][0] = 0;
    for (int i=0; i<=W; i++) C[0][i] = 0;

    for (int i=1; i<=H; i++) {
        for (int j=1; j<=W; j++) {
            if (c[i][j]==1) C[i][j] = 0;
            else {
                C[i][j] = min(C[i-1][j-1], min(C[i-1][j], C[i][j-1])) + 1;
                Max = max(Max, C[i][j]);
            }
        }
    }

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

int main() {
    scanf("%d %d", &H, &W);

    for (int i=1; i<=H; i++) {
        for (int j=1; j<=W; j++) {
            scanf("%d", &c[i][j]);
        }
    }

    dp();

    return 0;
}
