h,w = gets.split().map(&:to_i)
r = []
h.times do
	r << gets.split().map(&:to_i)
end

1.upto(h-1) do |i|
	1.upto(w-1) do |j|
		m = [r[i-1][j],r[i-1][j],r[i-1][j-1]].max
		if m == 1 || r[i][j] == 1
			next
		end
		r[i][j] = m-1
	end
end

p (r.map(&:min).min-1)**2