h, w = STDIN.gets.split.map(&:to_i)
c = h.times.map { STDIN.gets.split.map(&:to_i) }
dp = (h+1).times.map { (w+1).times.map { 0 } } 

(1..h).each do |i| 
  (1..w).each do |j| 
    if c[i-1][j-1] == 0
      dp[i][j] = [dp[i-1][j-1], dp[i-1][j], dp[i][j-1]].min + 1 
    else
      dp[i][j] = 0 
    end 
  end 
end

puts dp.flatten.max**2