You have a garden consisting entirely of grass and weeds. Your garden is described by an *n* × *m* grid, with rows numbered 1 to *n* from top to bottom, and columns 1 to *m* from left to right. Each cell is identified by a pair (*r*, *c*) which means that the cell is located at row *r* and column *c*. Each cell may contain either grass or weeds. For example, a 4 × 5 garden may look as follows (empty cells denote grass):

You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction — either left or right. And initially, you face right.

In one move you can do either one of these:

1) Move one cell in the direction that you are facing.
 -  if you are facing right: move from cell (*r*, *c*) to cell (*r*, *c* + 1) <center> <img class="tex-graphics" src="https://espresso.codeforces.com/c276e1bed94be3719d1c66b91ee47c682881a1a1.png" style="max-width: 100.0%;max-height: 100.0%;"/> </center> -  if you are facing left: move from cell (*r*, *c*) to cell (*r*, *c* - 1) <center> <img class="tex-graphics" src="https://espresso.codeforces.com/db006bc9e0faafd4c87d6af4370af935b196c207.png" style="max-width: 100.0%;max-height: 100.0%;"/> </center> -  if you were facing right previously, you will face left <center> <img class="tex-graphics" src="https://espresso.codeforces.com/6419636d10a92c8e4e1a225909f27a8d288a9e6a.png" style="max-width: 100.0%;max-height: 100.0%;"/> </center> -  if you were facing left previously, you will face right <center> <img class="tex-graphics" src="https://espresso.codeforces.com/8235e5e624726e6623d22e8e7de53a91868abfac.png" style="max-width: 100.0%;max-height: 100.0%;"/> </center> 
You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.

What is the minimum number of moves required to mow all the weeds?
The first line contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 150) — the number of rows and columns respectively. Then follow *n* lines containing *m* characters each — the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds. 

It is guaranteed that the top-left corner of the grid will contain grass.
4 5
GWGGW
GGWGG
GWGGG
WGGGG
11
3 3
GWW
WWW
WWG
7
1 1
G
0
4 3
GWW
WWW
WWW
WWG
11
6 5
GWWWW
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5
GWGGG
GGGGG
GGGGG
WGGGW
GGGGG
11
3 5
GWGGW
GGGGG
WGGWG
13
n, m = [int(x) for x in input().split(' ')]
matrix = [[0] * m for _ in range(n)]
ans = 0
last_row_pos = 0
last_row_true = 0
def find_index(arr):
    if all(element == 0 for element in arr):
        return False, -1, -1
    first_index = -1
    last_index = -1
    # find first 1 and the last 1, store their indexes
    for i in range(len(arr)):
        if arr[i] == 1 and first_index == -1:
            first_index = i
        if arr[i] == 1:
            last_index = i
    return True, first_index, last_index

# read data
for i in range(n):
    one_row = list(input())
    assert len(one_row) == m
    for j in range(m):
        matrix[i][j] = 1 if one_row[j] == 'W' else 0

# process data
for i in range(n):
    #found, first_index, last_index = find_index(matrix[i] if i % 2 == 0 else matrix[i][::-1])
    found, first_index, last_index = find_index(matrix[i])
    #print(found, first_index, last_index)
    if found:
        ans += i - last_row_true
        last_row_true = i
        if i % 2 == 0:
            if first_index < last_row_pos:
                ans += last_row_pos - first_index
                last_row_pos = first_index
            ans += last_index - last_row_pos
            last_row_pos = last_index
        else:
            if last_index > last_row_pos:
                ans += last_index - last_row_pos
                last_row_pos = last_index
            ans += last_row_pos - first_index
            last_row_pos = first_index

print(ans)
