h, w = STDIN.gets.split.map(&:to_i)
c = h.times.map { STDIN.gets.split.map { |v| 1-v.to_i } }

h.times.each do |i|
  w.times.each do |j|
    if c[i][j] >= 1
      c[i][j] = [c[i-1][j], c[i][j-1], c[i-1][j-1]].min + 1
    end
  end
end

puts c.flatten.max**2