H,W = list(map(int,input().split()))

s = [["#"]*(W+2)] + [["#"] + [c for c in eval(input())] + ["#"] for _ in [0]*H] + [["#"]*(W+2)]

ans = sum([sum([int(c == ".") for c in row]) for row in s])

s[1][1] = 1

ij = [[1,1]]

d = [[0,1],[0,-1],[1,0],[-1,0]]

cnt = 0

while ij[cnt:]:

    i,j = ij[cnt]

    for di,dj in d:

        if s[i+di][j+dj] == ".":

            s[i+di][j+dj] = s[i][j] + 1

            ij.append([i+di,j+dj])

            if i+di == H and j+dj == W:

                break

    cnt += 1

if s[H][W] == ".":

    ans = -1

else:

    ans -= s[H][W]

print(ans)
H,W = list(map(int,input().split()))

s = [[c=="." for c in eval(input())] for _ in [0]*H]



def bsf_dist_grid(grid,start):

    H = len(grid)

    W = len(grid[0])

    d = [[-1]*W for _ in [0]*H]

    d[start[0]][start[1]] = 0

    q = [start]

    while q:

        qq = []

        for xy in q:

            x,y = xy

            d0 = d[y][x]

            for dx,dy in ((1,0),(-1,0),(0,1),(0,-1)):

                if (not 0<=x+dx<W) or (not 0<=y+dy<H): continue

                if d[y+dy][x+dx] != -1: continue

                if not grid[y+dy][x+dx]: continue

                d[y+dy][x+dx] = d0+1

                qq.append((x+dx,y+dy))

        q = qq

    return d



d = bsf_dist_grid(s,(0,0))[-1][-1]

print(((sum(sum(a) for a in s)-d-1) if d>=0 else -1))
H, W = list(map(int, input().split()))
s = (
    [["#"] * (W + 2)]
    + [["#"] + [c for c in eval(input())] + ["#"] for _ in [0] * H]
    + [["#"] * (W + 2)]
)
ans = sum([sum([int(c == ".") for c in row]) for row in s])
s[1][1] = 1
ij = [[1, 1]]
d = [[0, 1], [0, -1], [1, 0], [-1, 0]]
cnt = 0
while ij[cnt:]:
    i, j = ij[cnt]
    for di, dj in d:
        if s[i + di][j + dj] == ".":
            s[i + di][j + dj] = s[i][j] + 1
            ij.append([i + di, j + dj])
            if i + di == H and j + dj == W:
                break
    cnt += 1
if s[H][W] == ".":
    ans = -1
else:
    ans -= s[H][W]
print(ans)

H, W = list(map(int, input().split()))
s = [[c == "." for c in eval(input())] for _ in [0] * H]


def bsf_dist_grid(grid, start):
    H = len(grid)
    W = len(grid[0])
    d = [[-1] * W for _ in [0] * H]
    d[start[0]][start[1]] = 0
    q = [start]
    while q:
        qq = []
        for xy in q:
            x, y = xy
            d0 = d[y][x]
            for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
                if (not 0 <= x + dx < W) or (not 0 <= y + dy < H):
                    continue
                if d[y + dy][x + dx] != -1:
                    continue
                if not grid[y + dy][x + dx]:
                    continue
                d[y + dy][x + dx] = d0 + 1
                qq.append((x + dx, y + dy))
        q = qq
    return d


d = bsf_dist_grid(s, (0, 0))[-1][-1]
print(((sum(sum(a) for a in s) - d - 1) if d >= 0 else -1))

-s = ( -    [["#"] * (W + 2)] -    + [["#"] + [c for c in eval(input())] + ["#"] for _ in [0] * H] -    + [["#"] * (W + 2)] -) -ans = sum([sum([int(c == ".") for c in row]) for row in s]) -s[1][1] = 1 -ij = [[1, 1]] -d = [[0, 1], [0, -1], [1, 0], [-1, 0]] -cnt = 0 -while ij[cnt:]: -    i, j = ij[cnt] -    for di, dj in d: -        if s[i + di][j + dj] == ".": -            s[i + di][j + dj] = s[i][j] + 1 -            ij.append([i + di, j + dj]) -            if i + di == H and j + dj == W: -                break -    cnt += 1 -if s[H][W] == ".": -    ans = -1 -else: -    ans -= s[H][W] -print(ans) +s = [[c == "." for c in eval(input())] for _ in [0] * H] + + +def bsf_dist_grid(grid, start): +    H = len(grid) +    W = len(grid[0]) +    d = [[-1] * W for _ in [0] * H] +    d[start[0]][start[1]] = 0 +    q = [start] +    while q: +        qq = [] +        for xy in q: +            x, y = xy +            d0 = d[y][x] +            for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)): +                if (not 0 <= x + dx < W) or (not 0 <= y + dy < H): +                    continue +                if d[y + dy][x + dx] != -1: +                    continue +                if not grid[y + dy][x + dx]: +                    continue +                d[y + dy][x + dx] = d0 + 1 +                qq.append((x + dx, y + dy)) +        q = qq +    return d + + +d = bsf_dist_grid(s, (0, 0))[-1][-1] +print(((sum(sum(a) for a in s) - d - 1) if d >= 0 else -1))