local H = io.read("*n")
local W = io.read("*n")
io.read("*l")

local map = {}
local whiteCount = 0
for h = 1, H do
	local str = io.read('*l')
	print(str)
	map[h] = {}
	for w = 1, W do
		if string.sub(str, w, w) == '.' then
			whiteCount = whiteCount + 1
			map[h][w] = 0
		else
			map[h][w] = -1
		end
	end
end

map[1][1] = 1
local stack = {}
table.insert(stack, {1, 1})
local function unvisit(h, w)
	if not map[h] then
		return false
	end
	return map[h][w] == 0
end
while(true) do
	if not stack[1] then
		print(-1)
		break
	end
	local t = stack[1]
	local h, w, steps = t[1], t[2], map[t[1]][t[2]]
	local neightbors = {
		{h - 1, w},
		{h, w - 1},
		{h + 1, w},
		{h, w + 1}
	}
	for k, v in ipairs(neightbors) do
		if v[1] == H and v[2] == W then
			print(whiteCount - (steps + 1))
			finded = true
			break
		end
		if unvisit(v[1], v[2]) then
			map[v[1]][v[2]] = steps + 1
			table.insert(stack, {v[1], v[2]})
		end
	end
	if finded then
		break
	end
	table.remove(stack, 1)
end