import java.util.*;

public class Main{
    public static void main (String[] args){
        Scanner SC = new Scanner(System.in);
        int R = SC.nextInt();
        int C = SC.nextInt();
        
        int[][] mat = new int[R][C];
        int[][] ans = new int[R][C];
        
        int max=0;
        int row,col;
        
        if (R == 0 || c == 0) {
            System.out.println(0);
            return;
        }
        for(row=0;row<R;row++) {
            for(col=0;col<C;col++) {
                mat[row][col] = SC.nextInt();
                ans[row][col] = 0;
            }
        }
        
        for(col=0;col<C;col++) {
          ans[0][col] = mat[0][col];
          if (ans[0][col] > max) max = ans[0][col];
        }
          
        for(row=0;row<R;row++) {
          ans[row][0] = mat[row][0];
          if (ans[row][0] > max) max = ans[row][0];
        }
        
        for(row=1;row<R;row++) {
            for(col=1;col<C;col++) {
                if(mat[row][col] == 1) {
                    
                    int min = Math.min(ans[row][col-1], Math.min(ans[row-1][col], ans[row-1][col-1]));
                    ans[row][col] = 1+ min;
                    max = Math.max(max, ans[row][col]);
                }
            }
        }
        System.out.println(max*max);
    }
}