height, width = gets.split.map &:to_i
g = Array.new(height)
dp = Array.new(height).map { Array.new(width) }
max = 0

(0...height).each do |i|
  g[i] = gets.split.map &:to_i
end

(0...height).each do |i|
  if g[i][0] == 0
    dp[i][0] = 1
    max = 1
  else
    dp[i][0] = 0
  end
end

(0...width).each do |i|
  if g[0][i] == 0
    dp[0][i] = 1
    max = 1
  else
    dp[0][i] = 0
  end
end

(1...height).each do |i|
  (1...width).each do |j|
    if g[i][j] == 1
      dp[i][j] = 0
    else
      dp[i][j] = [dp[i-1][j-1], dp[i][j-1], dp[i-1][j]].min + 1
      max = max > dp[i][j] ? max : dp[i][j]
    end
  end
end

puts max**2