#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
bool grid[155][155];
int _left[155], _right[155];
int main() {
  int m, n, i, j;
  char ch;
  scanf("%d%d", &m, &n);
  for (i = 1; i <= m; ++i) {
    _left[i] = 200;
    for (j = 1; j <= n; ++j) {
      cin >> ch;
      if (ch == 'G')
        grid[i][j] = false;
      else
        grid[i][j] = true;
      if (grid[i][j]) {
        _left[i] = min(j, _left[i]);
        _right[i] = max(j, _right[i]);
      }
    }
  }
  int sum = m - 1;
  int cur = 1;
  for (i = 1; i < m; ++i) {
    if (i % 2) {
      if (max(_right[i], _right[i + 1]) < cur) continue;
      sum += (max(_right[i], _right[i + 1]) - cur);
      cur = max(_right[i], _right[i + 1]);
    } else {
      if (min(_left[i], _left[i + 1]) > cur) continue;
      sum += cur - min(_left[i], _left[i + 1]);
      cur = min(_left[i], _left[i + 1]);
    }
  }
  if (i % 2) {
    if (_right[i] == 0)
      ;
    else
      sum += _right[i] - cur;
  } else {
    if (_left[i] == 200)
      ;
    else
      sum += cur - _left[i];
  }
  for (i = m; i >= 1; --i) {
    if (_right[i] == 0)
      --sum;
    else
      break;
  }
  if (sum < 0)
    printf("0\n");
  else
    printf("%d\n", sum);
  return 0;
}
