
-- B
-- s = io.read()
local H = io.read('*n')
local W = io.read('*n')
io.read('*l')
local map = {}
for x = 1, H do
	map[x] = io.read('*l')
end
local function solve()
	local stepMap = {}
	local backtracking = {}
	for i = 1, W do
		stepMap[i] = {}
	end

	local whiteNum = 0
	for i = 1, H do
		for j = 1, W do
			if string.sub(map[i], j, j) == '.' then
				whiteNum = whiteNum + 1
			end
		end
	end

	local function isWhite(x, y)
		return string.sub(map[y], x, x) == '.'
	end
	local function canset(x, y, n)
		if x < 1 or y < 1 or x > W or y > H then
			return false
		end
		local oldn = stepMap[x][y]
		-- print('oldn', oldn, x, y, n)
		if oldn and oldn <= n then
			return false
		end
		return isWhite(x, y)
	end
	local x = 1;y = 1;n = 1;
	table.insert(backtracking, {x, y, n})
	stepMap[1][1] = 1
	while(true) do
		n = n + 1
		if canset(x - 1, y, n) then
			stepMap[x - 1][y] = n
			table.insert(backtracking, {x - 1, y, n})
			x = x - 1
		elseif canset(x, y - 1, n) then
			stepMap[x][y - 1] = n
			table.insert(backtracking, {x, y - 1, n})
			y = y - 1
		elseif canset(x + 1, y, n) then
			stepMap[x + 1][y] = n
			table.insert(backtracking, {x + 1, y, n})
			x = x + 1
		elseif canset(x, y + 1, n) then
			stepMap[x][y + 1] = n
			table.insert(backtracking, {x, y + 1, n})
			y = y + 1
		else
			local count = #backtracking
			if count == 1 then
				break
			else
				table.remove(backtracking, count)
				x, y, n = unpack(backtracking[count - 1])
			end
		end
	end
	local ret = stepMap[W][H]
	if ret then
		return whiteNum - ret
	else
		return -1
	end
end
print(solve())
