local h = io.read("*number")
local w = io.read("*number")
local black = 0
local white = 0

for i=1, h do
	for j=1, w do
		local t = io.read()
		if t == "." then
			white = white + 1
		elseif t == "#" then
			black = black + 1
		end
	end
end

local function getABC()
	local n = h + w - 1
	if white < n then
		print(-1)
		return
	end
	local sum = h*w
	local num = sum - n - black
	if num < 0 then
		print(-1)
		return
	end
	print(num)
end

getABC()