#include <bits/stdc++.h>
using namespace std;
const int maxn = 150 + 10;
char s[maxn][maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  char s[155][155];
  int i, j;
  for (i = 0; i < n; i++) scanf("%s", s[i]);
  int x = 0, y = 0, sum = 0;
  for (i = 0; i < n; i++) {
    if (i % 2 == 0)
      j = 0;
    else
      j = m - 1;
    for (; j >= 0 && j < m;) {
      if (s[i][j] == 'W') {
        sum += abs(i - x) + abs(j - y);
        x = i;
        y = j;
      }
      if (i % 2 == 0)
        j++;
      else
        j--;
    }
  }
  printf("%d\n", sum);
}
