#d2801. 走不出的迷宫

走不出的迷宫

The Inescapable Maze

Problem Description

There is a maze of HH rows and WW columns (rows are numbered 11 to HH from top to bottom, columns 11 to WW from left to right). The maze is given as an H×WH \times W matrix of . and #, where . is open ground you can pass through and # is a wall you cannot cross.

A person starts at (1,1)(1, 1) and at each step may move only one cell to the right or one cell down, without leaving the maze. He keeps walking until there is no legal move left, then stops.

What is the maximum number of cells he can pass through?

Input Format

The first line contains two integers HH and WW: the maze has HH rows and WW columns.

Then follows an H×WH \times W matrix of . and # describing the maze.

Note: (1,1)(1, 1) is guaranteed to be ..

Output Format

Output one integer: the maximum number of cells that can be visited.

Sample Input 1

3 4
.#..
..#.
..##

Sample Output 1

4

Sample Input 2

1 1
.

Sample Output 2

1

Sample Input 3

5 5
.....
.....
.....
.....
.....

Sample Output 3

9

Constraints

1≤H,W≤1001 \leq H, W \leq 100.