#C8716. Minimum Moves in a Grid

    ID: 52729 Type: Default 1000ms 256MiB

Minimum Moves in a Grid

Minimum Moves in a Grid

You are given a grid of size \(R \times C\) where each cell is either an empty cell denoted by '.' or an obstacle denoted by '#' . Your task is to determine the minimum number of moves required to travel from the top-left corner (cell \((0, 0)\)) to the bottom-right corner (cell \((R-1, C-1)\)). You can move in four directions: up, down, left, and right. If it is impossible to reach the destination, output \(-1\).

Note: The grid is provided via standard input and the result should be printed to standard output.

inputFormat

The first line contains two integers \(R\) and \(C\) representing the number of rows and columns in the grid. This is followed by \(R\) lines, each containing a string of length \(C\) representing a row of the grid. A dot ('.') represents an empty cell and a hash ('#') represents an obstacle.

Example:

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

outputFormat

Output a single integer which is the minimum number of moves required to reach the bottom-right cell from the top-left cell. If the destination cannot be reached, print \(-1\).

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