import queue
import copy
import math

# 2つの入力を空白で分割し、数値化
H, W = map(int, input().split())

maze = []
for h in range(0, H):
    row = input()
    maze.append(list(row))


def no_wall(maze):
    for row in maze:
        if "#" in row:
            return False
    return True

answering_maze = copy.deepcopy(maze)


def in_range(row, col, maze):
    if 0 <= row < len(maze):
        if 0 <= col <len(maze[row]):
            return maze[row][col] == "."
    return False


def can_visit(row, col, maze):
    if 0 <= row < len(maze):
        if 0 <= col <len(maze[row]):
            return maze[row][col] != True
    return False


def find_start_and_goal(maze):
    # 右下へ。だめなら上
    right_direction = 0
    left_direction = 0

    visited_maze = copy.deepcopy(maze)

    for r, row in zip(range(0, len(maze)), maze):
        for c, cell in zip(range(0, len(row)), row):
            # 初めて見つけた点から探す
            if cell == ".":
                rr = r
                cc = c
                while True:
                    # 右
                    if in_range(rr, cc + 1, maze) and can_visit(rr, cc + 1, visited_maze):
                        right_direction += 1
                        cc += 1
                    # 下
                    elif in_range(rr + 1, cc, maze) and can_visit(rr + 1, cc, visited_maze):
                        right_direction += 1
                        rr += 1
                    # 上
                    elif in_range(rr - 1, cc, maze) and can_visit(rr - 1, cc, visited_maze):
                        right_direction += 1
                        rr -= 1
                    else:
                        break
                    visited_maze[rr][cc] = True

                rr = r
                cc = c
                visited_maze2 = copy.deepcopy(maze)
                while True:
                    # 左
                    if in_range(rr, cc - 1, maze) and can_visit(rr, cc - 1, visited_maze2):
                        left_direction += 1
                        cc -= 1
                    # 下
                    elif in_range(rr + 1, cc, maze) and can_visit(rr + 1, cc, visited_maze2):
                        left_direction += 1
                        rr += 1
                    # 上
                    elif in_range(rr - 1, cc, maze) and can_visit(rr - 1, cc, visited_maze2):
                        left_direction += 1
                        rr -= 1
                    else:
                        break
                    visited_maze2[rr][cc] = True

                return right_direction + left_direction


if no_wall(maze):
    print(H + W - 2)
else:
    print(find_start_and_goal(maze))
