import scala.io.StdIn

object Main extends App {

  val Array(h, w) = StdIn.readLine().split(' ').map(_.toInt)

  val tiles = (0 until h).map(_ => StdIn.readLine().split(' ')).toArray
  val square = Array.fill[Int](h + 1, w + 1)(0)
  var max = 0

  (1 to h).foreach { i =>
    (1 to w).foreach { k =>
      square(i)(k) = if (tiles(i - 1)(k - 1) == "0") {
        (scala.math.min(square(i)(k - 1),
          scala.math.min(square(i - 1)(k - 1), square(i - 1)(k)))) + 1
      } else {
        0
      }

      max = scala.math.max(square(i)(k), max)
    }
  }

  println(max * max)

}
