#abc213e. [abc213_e]Stronger Takahashi

[abc213_e]Stronger Takahashi

Problem Statement

There is a town divided into a grid of cells with HH rows and WW columns. The cell at the ii-th row from the top and jj-th column from the left is a passable space if Si,jS_{i,j} is . and a block if Si,jS_{i,j} is #.

Takahashi will go from his house to a fish market. His house is in the cell at the top-left corner, and the fish market is in the cell at the bottom-right corner.

Takahashi can move one cell up, down, left, or right to a passable cell. He cannot leave the town. He cannot enter a block, either. However, his physical strength allows him to destroy all blocks in a square region with 2times22\\times 2 cells of his choice with one punch, making these cells passable.

Find the minimum number of punches needed for Takahashi to reach the fish market.

Constraints

  • 2leqH,Wleq5002 \\leq H,W \\leq 500
  • HH and WW are integers.
  • Si,jS_{i,j} is . or #.
  • S1,1S_{1,1} and SH,WS_{H,W} are ..

Input

Input is given from Standard Input in the following format:

HH WW S1,1ldotsS1,WS_{1,1} \\ldots S_{1,W} vdots\\vdots SH,1ldotsSH,WS_{H,1} \\ldots S_{H,W}

Output

Print the answer.


Sample Input 1

5 5
..#..
#.#.#
##.##
#.#.#
..#..

Sample Output 1

1

He can reach the fish market by, for example, destroying the blocks in the square region with 2times22\\times 2 cells marked * below.

..#..
#.**#
##**#
#.#.#
..#..```

It is not required that all of the $2\\times 2$ cells in the region to punch are blocks.

* * *

### Sample Input 2

```plain
5 7
.......
######.
.......
.######
.......

Sample Output 2

0

He can reach the fish market without destroying blocks, though he has to go a long way around.


Sample Input 3

8 8
.#######
########
########
########
########
########
########
#######.

Sample Output 3

5