G. Minecraft
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

The side view of the Minecraft game world is represented as a rectangular grid of dimensions $$$h \times w$$$ — a vertical cross-section of the ground. Each cell in this grid can be empty, occupied by a dirt block, or occupied by a gold block. Beneath the bottom edge of the grid lies lava. Each block is supported either by another block or by lava. Additionally, gravity operates in Minecraft; thus, an object will fall downward if it lacks support.

Initially, the player stands on an empty cell located above the leftmost occupied cell.

The player may perform the following actions:

  1. Mine the block directly below if there is no lava beneath that block. After this action, the player moves down one cell.
  2. Mine the block to the right. If this block is not the uppermost in its column, all blocks above it will fall down. The player does not move to the right.
  3. Place a dirt block in an empty cell to the right. If there is an empty cell beneath this block, it will fall down.
  4. Move into an empty cell to the right. If the cell beneath the player is empty, the player will fall down. The player may safely fall from any height.
  5. If the player is not at the upper boundary, they may jump up one cell. While in the air, the player can place a dirt block underneath themselves or perform any of the actions listed above.

The objective of the player is to mine all gold blocks and reach the right edge of the grid using the minimum number of block creation and destruction operations.

Input

The first line of the input file contains two integers $$$h$$$ and $$$w$$$ ($$$5 \leq h, w \leq 100$$$) — the height and width of the grid, respectively. The next $$$h$$$ lines contain $$$w$$$ characters each, describing the grid: the character "." denotes an empty cell, the character "#" denotes a dirt block, and the character "G" denotes a gold block. There are no gold blocks on the left and right boundaries. All cells at the top boundary are empty. All cells at the bottom boundary are occupied by dirt blocks. There is no empty block located underneath any occupied block.

Output

The output file should contain a single integer — the minimum number of block creation and destruction operations required to achieve the objective.

Examples
Input
5 5
.....
#..#.
##.##
#GGG#
#####
Output
5
Input
5 5
.....
#..G.
#..##
#####
#####
Output
1
Input
8 5
.....
.....
....#
....#
....#
.#.G#
#####
#####
Output
4