시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 (추가 시간 없음) 1024 MB327633.333%

문제

Walking across a huge parking lot is not only time consuming but also challenging because cars block your way and you may even get lost!

Imagine you are walking across a parking lot of r rows and c columns of parking spots. All parking spots have a size of a unit square. A parking spot either is empty or contains a parked car. You can walk across an empty parking spot in any direction, but can only walk along the boundaries of a parking spot if there’s a parked car in it. You start at the top-left corner of the parking lot and walk at a constant speed of one unit distance per second. If you pick the fastest route, in how many seconds can you walk to the bottom-right corner of the parking lot?

The image illustrates two possible routes for the parking lot in the first sample case. The blue route is the fastest route in this case. The red route shows that you can walk along the boundaries of parked cars.

입력

The first line of input has two integers r and c (1 ≤ r, c ≤ 50). The next r lines each have a string of c characters giving one row of parking spots from top to bottom. A dot ‘.’ indicates an empty parking spot and a hash ‘#’ indicates a parking spot with a parked car.

출력

Output the smallest amount of time in seconds you need to walk to the bottom-right corner of the parking lot. Your answer is considered correct if it has an absolute or relative error of at most 10−6 from the correct answer.

예제 입력 1

4 4
..#.
.#.#
###.
.#..

예제 출력 1

5.886349517

예제 입력 2

2 2
##
##

예제 출력 2

4.000000000