#include <bits/stdc++.h>
using namespace std;
char grid[150 + 10][150 + 10];
int n, m;
int Left[150 + 10], Right[150 + 10];
int d[150 + 10];
void init() {
  memset(Left, -1, sizeof Left);
  memset(Right, -1, sizeof Right);
  memset(d, 0, sizeof d);
  for (int i = 0; i < n; ++i) {
    int l = 0, r = m - 1;
    while (grid[i][l] == 'G' && l < m) ++l;
    if (l < m) Left[i] = l;
    while (grid[i][r] == 'G' && r >= 0) --r;
    if (r >= 0) Right[i] = r;
    if (Right[i] != -1) d[i] = r - l;
  }
  int cnt = 0;
  while (1) {
    bool check = false;
    for (int i = 0; i < n - 1; ++i)
      if (i % 2 == 0 && Right[i] == -1 && Right[i + 1] != -1) {
        Right[i] = Left[i] = Right[i + 1];
        check = true;
      } else if (i % 2 > 0 && Left[i] == -1 && Left[i + 1] != -1) {
        Left[i] = Right[i] = Left[i + 1];
        check = true;
      }
    if (!check) break;
  }
}
void solve() {
  int res = 0;
  if (n == 1 && Right[0] == -1) {
    cout << res << endl;
    return;
  }
  for (int i = 0; i < n; ++i) {
    if (Right[i] == -1) break;
    if (i % 2 == 0) {
      if (i == 0)
        res += Right[i];
      else
        res += abs(Left[i - 1] - Left[i]) + 1 + d[i];
    } else
      res += abs(Right[i - 1] - Right[i]) + d[i] + 1;
  }
  cout << res << endl;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", grid[i]);
  init();
  solve();
  return 0;
}
