from collections import deque

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

white=0

s=[]

for y in range(H):

    line=eval(input())

    white+=line.count('.')

    s.append(list(line))



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

q_append=q.append

q_popleft=q.popleft

while q:

    x,y,l=q_popleft()

    if s[y][x]!='.':

        continue

    if x==W-1 and y==H-1:

        print((white-l))

        break

    s[y][x]='*'

    for d in [(1,0),(0,1),(-1,0),(0,-1)]:

        nx, ny=(x+d[0],y+d[1])

        if 0<=nx<W and 0<=ny<H:

            q_append((nx,ny,l+1))

else:

    print((-1))

    

from queue import Queue

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

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



white=sum([1 if s[y][x]=='.' else 0 for x in range(W) for y in range(H)])

used=[[False for x in range(W)] for y in range(H)]

q=Queue()

q.put((0,0,1))

while True:

    if q.empty():

        print((-1))

        break

    x,y,l=q.get()

    if used[y][x]:

        continue

    if x==W-1 and y==H-1:

        print((white-l))

        break

    used[y][x]=True

    for d in [(1,0),(0,1),(-1,0),(0,-1)]:

        nx=x+d[0]

        ny=y+d[1]

        if ny>=0 and ny<H and nx>=0 and nx<W:

            if s[ny][nx]=='.':

                q.put((nx,ny,l+1))

    

from collections import deque

H, W = list(map(int, input().split()))
white = 0
s = []
for y in range(H):
    line = eval(input())
    white += line.count(".")
    s.append(list(line))
q = deque([(0, 0, 1)])
q_append = q.append
q_popleft = q.popleft
while q:
    x, y, l = q_popleft()
    if s[y][x] != ".":
        continue
    if x == W - 1 and y == H - 1:
        print((white - l))
        break
    s[y][x] = "*"
    for d in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        nx, ny = (x + d[0], y + d[1])
        if 0 <= nx < W and 0 <= ny < H:
            q_append((nx, ny, l + 1))
else:
    print((-1))

from queue import Queue

H, W = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(H)]
white = sum([1 if s[y][x] == "." else 0 for x in range(W) for y in range(H)])
used = [[False for x in range(W)] for y in range(H)]
q = Queue()
q.put((0, 0, 1))
while True:
    if q.empty():
        print((-1))
        break
    x, y, l = q.get()
    if used[y][x]:
        continue
    if x == W - 1 and y == H - 1:
        print((white - l))
        break
    used[y][x] = True
    for d in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        nx = x + d[0]
        ny = y + d[1]
        if ny >= 0 and ny < H and nx >= 0 and nx < W:
            if s[ny][nx] == ".":
                q.put((nx, ny, l + 1))

-from collections import deque +from queue import Queue -white = 0 -s = [] -for y in range(H): -    line = eval(input()) -    white += line.count(".") -    s.append(list(line)) -q = deque([(0, 0, 1)]) -q_append = q.append -q_popleft = q.popleft -while q: -    x, y, l = q_popleft() -    if s[y][x] != ".": +s = [list(eval(input())) for _ in range(H)] +white = sum([1 if s[y][x] == "." else 0 for x in range(W) for y in range(H)]) +used = [[False for x in range(W)] for y in range(H)] +q = Queue() +q.put((0, 0, 1)) +while True: +    if q.empty(): +        print((-1)) +        break +    x, y, l = q.get() +    if used[y][x]: -    s[y][x] = "*" +    used[y][x] = True -        nx, ny = (x + d[0], y + d[1]) -        if 0 <= nx < W and 0 <= ny < H: -            q_append((nx, ny, l + 1)) -else: -    print((-1)) +        nx = x + d[0] +        ny = y + d[1] +        if ny >= 0 and ny < H and nx >= 0 and nx < W: +            if s[ny][nx] == ".": +                q.put((nx, ny, l + 1))