from collections import deque





def bfs(start):

    q = deque([[start]])

    visited = set()

    while q:

        path = q.popleft()

        i, j = path[-1]

        if (i, j) == (H - 1, W - 1):

            return path

        for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]:

            ni, nj = i + di, j + dj

            if (

                0 <= ni < H

                and 0 <= nj < W

                and field[ni][nj] != "#"

                and (ni, nj) not in visited

            ):

                q.append(path + [(ni, nj)])

                visited.add((ni, nj))





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

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

shortest_path = bfs((0, 0))

if shortest_path is None:

    print((-1))

    exit()

ans = 0

for i in range(H):

    for j in range(W):

        if field[i][j] == "." and (i, j) not in shortest_path:

            ans += 1

print(ans)

from collections import deque





def bfs(start, goal):

    q = deque([[start]])

    visited = set()

    while q:

        path = q.popleft()

        i, j = path[-1]

        if (i, j) == goal:

            return path

        for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]:

            ni, nj = i + di, j + dj

            if not (0 <= ni < H and 0 <= nj < W and field[ni][nj] == "."):

                continue

            if (ni, nj) not in visited:

                q.append(path + [(ni, nj)])

                visited.add((ni, nj))

    return []





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

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

shortest_path = bfs((0, 0), (H - 1, W - 1))

if shortest_path:

    print((sum(v == "." for row in field for v in row) - len(shortest_path)))

else:

    print((-1))

from collections import deque


def bfs(start):
    q = deque([[start]])
    visited = set()
    while q:
        path = q.popleft()
        i, j = path[-1]
        if (i, j) == (H - 1, W - 1):
            return path
        for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            ni, nj = i + di, j + dj
            if (
                0 <= ni < H
                and 0 <= nj < W
                and field[ni][nj] != "#"
                and (ni, nj) not in visited
            ):
                q.append(path + [(ni, nj)])
                visited.add((ni, nj))


H, W = list(map(int, input().split()))
field = [eval(input()) for _ in range(H)]
shortest_path = bfs((0, 0))
if shortest_path is None:
    print((-1))
    exit()
ans = 0
for i in range(H):
    for j in range(W):
        if field[i][j] == "." and (i, j) not in shortest_path:
            ans += 1
print(ans)

from collections import deque


def bfs(start, goal):
    q = deque([[start]])
    visited = set()
    while q:
        path = q.popleft()
        i, j = path[-1]
        if (i, j) == goal:
            return path
        for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            ni, nj = i + di, j + dj
            if not (0 <= ni < H and 0 <= nj < W and field[ni][nj] == "."):
                continue
            if (ni, nj) not in visited:
                q.append(path + [(ni, nj)])
                visited.add((ni, nj))
    return []


H, W = list(map(int, input().split()))
field = [eval(input()) for _ in range(H)]
shortest_path = bfs((0, 0), (H - 1, W - 1))
if shortest_path:
    print((sum(v == "." for row in field for v in row) - len(shortest_path)))
else:
    print((-1))

-def bfs(start): +def bfs(start, goal): -        if (i, j) == (H - 1, W - 1): +        if (i, j) == goal: -            if ( -                0 <= ni < H -                and 0 <= nj < W -                and field[ni][nj] != "#" -                and (ni, nj) not in visited -            ): +            if not (0 <= ni < H and 0 <= nj < W and field[ni][nj] == "."): +                continue +            if (ni, nj) not in visited: +    return [] -shortest_path = bfs((0, 0)) -if shortest_path is None: +shortest_path = bfs((0, 0), (H - 1, W - 1)) +if shortest_path: +    print((sum(v == "." for row in field for v in row) - len(shortest_path))) +else: -    exit() -ans = 0 -for i in range(H): -    for j in range(W): -        if field[i][j] == "." and (i, j) not in shortest_path: -            ans += 1 -print(ans)