#abc088d. [abc088_d]Grid Repainting

[abc088_d]Grid Repainting

Problem statement

We have an HtimesWH \\times W grid whose squares are painted black or white. The square at the ii-th row from the top and the jj-th column from the left is denoted as (i,j)(i, j).
Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1,1)(1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H,W)(H, W) passing only white squares.
Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1,1)(1, 1) and (H,W)(H, W). Also, changes of color must all be carried out before the beginning of the game.
When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print \-1\-1 if the game cannot be completed, that is, Kenus can never reach square (H,W)(H, W) regardless of how Snuke changes the color of the squares.

The color of the squares are given to you as characters si,js_{i, j}. If square (i,j)(i, j) is initially painted by white, si,js_{i, j} is .; if square (i,j)(i, j) is initially painted by black, si,js_{i, j} is #.

Constraints

  • HH is an integer between 22 and 5050 (inclusive).
  • WW is an integer between 22 and 5050 (inclusive).
  • si,js_{i, j} is . or # (1leqileqH,1leqjleqW)(1 \\leq i \\leq H, 1 \\leq j \\leq W).
  • s1,1s_{1, 1} and sH,Ws_{H, W} are ..

Input

Input is given from Standard Input in the following format:

HH WW s1,1s1,2s1,3...s1,Ws_{1, 1}s_{1, 2}s_{1, 3} ... s_{1, W} s2,1s2,2s2,3...s2,Ws_{2, 1}s_{2, 2}s_{2, 3} ... s_{2, W} :: :: sH,1sH,2sH,3...sH,Ws_{H, 1}s_{H, 2}s_{H, 3} ... s_{H, W}

Output

Print the maximum possible score that Snuke can achieve, or print \-1\-1 if the game cannot be completed.


Sample Input 1

3 3
..#
#..
...

Sample Output 1

2

The score 22 can be achieved by changing the color of squares as follows:

Explanation of Sample 1


Sample Input 2

10 37
.....................................
...#...####...####..###...###...###..
..#.#..#...#.##....#...#.#...#.#...#.
..#.#..#...#.#.....#...#.#...#.#...#.
.#...#.#..##.#.....#...#.#.###.#.###.
.#####.####..#.....#...#..##....##...
.#...#.#...#.#.....#...#.#...#.#...#.
.#...#.#...#.##....#...#.#...#.#...#.
.#...#.####...####..###...###...###..
.....................................

Sample Output 2

209