#C9826. Minimum Moves to Reach Destination

    ID: 53962 Type: Default 1000ms 256MiB

Minimum Moves to Reach Destination

Minimum Moves to Reach Destination

You are given a grid with \( R \) rows and \( C \) columns. Each cell in the grid is either an open cell represented by a dot (\( . \)) or a blocked cell represented by a hash (\( # \)). Your task is to determine the minimum number of moves needed to travel from the top-left corner (cell \( (0,0) \)) to the bottom-right corner (cell \( (R-1,C-1) \)). Moves are allowed in four directions: up, down, left, and right.

If it is impossible to reach the destination, output \( -1 \). Note that both the starting and ending cells are part of the grid, and the indices start at 0.

inputFormat

The first line contains two integers \( R \) and \( C \) representing the number of rows and columns respectively. The following \( R \) lines each contain a string of length \( C \) describing the grid. Each character in a string is either a dot (\( . \)) indicating an open cell or a hash (\( # \)) indicating a blocked cell.

outputFormat

Output a single integer: the minimum number of moves required to reach the destination, or \( -1 \) if it is impossible.

## sample
4 4
....
..##
..#.
....
6