from collections import deque

import numpy as np



H,W = [int(i) for i in input().split()]

l = [list(eval(input())) for _ in range(H)]

check = [[False]*W for _ in range(H)]

ans = [[0]*W for _ in range(H)]



q = deque()

q.append([0,0])

check[0][0] = True



while q:

    i,j = q.popleft()

    for next_i, next_j in [[i+1,j], [i-1,j], [i,j+1], [i,j-1]]:

        if 0 <= next_i < H and 0 <= next_j < W:

            if not check[next_i][next_j] and l[next_i][next_j] != '#':

                q.append([next_i,next_j])

                check[next_i][next_j] = True

                ans[next_i][next_j] = ans[i][j]+1



cnt = 0

for i in range(H):

    for j in range(W):

        if l[i][j] == '.':

            cnt += 1



if ans[H-1][W-1]:

    print((cnt-ans[H-1][W-1]-1))

else:

    print((-1))

from collections import deque

import numpy as np



H,W = [int(zz) for zz in input().split()]

map = [['#']*(W+2) for _ in range(H+2)]



ans = 0

for i in range(1,H+1):

    tmp = eval(input())

    s = list('#'+tmp+'#')

    map[i] = s

    ans += tmp.count('#')



check = [[1]*(W+2) for _ in range(H+2)]

count = [[0]*(W+2) for _ in range(H+2)]

q = deque([(1,1)])

check[1][1] = 0

while q:

    x,y = q.popleft()

    for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:

        if check[x+i][y+j] and map[x+i][y+j] == '.':

            check[x+i][y+j] = 0

            q.append((x+i,y+j))

            count[x+i][y+j] = count[x][y]+1

zz = count[H][W]

if zz == 0:

    print((-1))

else:

    count = set((np.array(count)).flatten())

    for i in count:

        if i > zz:

            ans -= 1

    print((H*W-len(count)-ans))

from collections import deque
import numpy as np

H, W = [int(i) for i in input().split()]
l = [list(eval(input())) for _ in range(H)]
check = [[False] * W for _ in range(H)]
ans = [[0] * W for _ in range(H)]
q = deque()
q.append([0, 0])
check[0][0] = True
while q:
    i, j = q.popleft()
    for next_i, next_j in [[i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]]:
        if 0 <= next_i < H and 0 <= next_j < W:
            if not check[next_i][next_j] and l[next_i][next_j] != "#":
                q.append([next_i, next_j])
                check[next_i][next_j] = True
                ans[next_i][next_j] = ans[i][j] + 1
cnt = 0
for i in range(H):
    for j in range(W):
        if l[i][j] == ".":
            cnt += 1
if ans[H - 1][W - 1]:
    print((cnt - ans[H - 1][W - 1] - 1))
else:
    print((-1))

from collections import deque
import numpy as np

H, W = [int(zz) for zz in input().split()]
map = [["#"] * (W + 2) for _ in range(H + 2)]
ans = 0
for i in range(1, H + 1):
    tmp = eval(input())
    s = list("#" + tmp + "#")
    map[i] = s
    ans += tmp.count("#")
check = [[1] * (W + 2) for _ in range(H + 2)]
count = [[0] * (W + 2) for _ in range(H + 2)]
q = deque([(1, 1)])
check[1][1] = 0
while q:
    x, y = q.popleft()
    for i, j in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        if check[x + i][y + j] and map[x + i][y + j] == ".":
            check[x + i][y + j] = 0
            q.append((x + i, y + j))
            count[x + i][y + j] = count[x][y] + 1
zz = count[H][W]
if zz == 0:
    print((-1))
else:
    count = set((np.array(count)).flatten())
    for i in count:
        if i > zz:
            ans -= 1
    print((H * W - len(count) - ans))

-H, W = [int(i) for i in input().split()] -l = [list(eval(input())) for _ in range(H)] -check = [[False] * W for _ in range(H)] -ans = [[0] * W for _ in range(H)] -q = deque() -q.append([0, 0]) -check[0][0] = True +H, W = [int(zz) for zz in input().split()] +map = [["#"] * (W + 2) for _ in range(H + 2)] +ans = 0 +for i in range(1, H + 1): +    tmp = eval(input()) +    s = list("#" + tmp + "#") +    map[i] = s +    ans += tmp.count("#") +check = [[1] * (W + 2) for _ in range(H + 2)] +count = [[0] * (W + 2) for _ in range(H + 2)] +q = deque([(1, 1)]) +check[1][1] = 0 -    i, j = q.popleft() -    for next_i, next_j in [[i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]]: -        if 0 <= next_i < H and 0 <= next_j < W: -            if not check[next_i][next_j] and l[next_i][next_j] != "#": -                q.append([next_i, next_j]) -                check[next_i][next_j] = True -                ans[next_i][next_j] = ans[i][j] + 1 -cnt = 0 -for i in range(H): -    for j in range(W): -        if l[i][j] == ".": -            cnt += 1 -if ans[H - 1][W - 1]: -    print((cnt - ans[H - 1][W - 1] - 1)) +    x, y = q.popleft() +    for i, j in [(1, 0), (0, 1), (-1, 0), (0, -1)]: +        if check[x + i][y + j] and map[x + i][y + j] == ".": +            check[x + i][y + j] = 0 +            q.append((x + i, y + j)) +            count[x + i][y + j] = count[x][y] + 1 +zz = count[H][W] +if zz == 0: +    print((-1)) -    print((-1)) +    count = set((np.array(count)).flatten()) +    for i in count: +        if i > zz: +            ans -= 1 +    print((H * W - len(count) - ans))