#include <bits/stdc++.h>
using namespace std;
char c[152][152];
pair<int, int> cap[152];
int poz[152];
int main() {
  int i, j, n, m, col;
  int rasp = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) cin >> c[i][j];
  cap[n + 1] = {m + 1, 0};
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m && c[i][j] == 'G'; j++)
      ;
    cap[i].first = j;
    for (j = m; j >= 1 && c[i][j] == 'G'; j--)
      ;
    cap[i].second = j;
  }
  for (i = n; i >= 1 && cap[i].first > m; i--)
    ;
  n = i;
  col = 1;
  for (i = 1; i <= n; i++) {
    if (i & 1) {
      if (cap[i].first <= m) {
        rasp = rasp + cap[i].second - col;
        col = cap[i].second;
      }
      if (cap[i + 1].second > col) {
        rasp = rasp + cap[i + 1].second - col;
        col = cap[i + 1].second;
      }
    } else {
      if (cap[i].first <= m) {
        rasp = rasp + col - cap[i].first;
        col = cap[i].first;
      }
      if (cap[i + 1].first < col) {
        rasp = rasp + col - cap[i + 1].first;
        col = cap[i + 1].first;
      }
    }
  }
  cout << max(rasp + n - 1, 0);
  return 0;
}
