import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val H, W = sc.nextInt()
  val area = Array.ofDim[Int](H+1,W+1)
  for (i <- 1 to H; j <- 1 to W) area(i)(j) = 1-sc.nextInt()
  for (i <- 0 to H) area(i)(0) = 0
  for (j <- 0 to W) area(0)(j) = 0

  class Metrix(height:Int, width:Int, area:Array[Array[Int]]) {
    val maxLength = height min width
    def solver():Int = {
      var length = 0
      for (i <- 1 to height; j <- 1 to width) {
        if (area(i)(j) > 0) {
          area(i)(j) = Seq(area(i-1)(j-1),area(i-1)(j),area(i)(j-1)).min+1
          length = length max area(i)(j)
        }
      } 
      length*length
    }
  }

  val mt = new Metrix(H,W,area)
  println(mt.solver())

}
