#include <bits/stdc++.h>
using namespace std;
int N, M, i, j, k, cnt;
char a[200][200];
int x, y;
int est[200], L[200], R[200];
int main() {
  scanf("%d %d", &N, &M);
  gets(a[197]);
  for (i = 0; i < N; i++) gets(a[i]);
  for (i = 0; i < N; i++) {
    L[i] = -1;
    x = -1;
    for (j = 0; j < M; j++)
      if (a[i][j] == 'W') {
        est[i]++;
        if (L[i] == -1) L[i] = j;
        x = j;
      }
    if (x != -1) R[i] = x;
  }
  x = y = 0;
  for (i = 0; i < N; i++) {
    if (i % 2 == 0) {
      if (est[i]) {
        cnt += R[i] - y;
        x = i;
        y = R[i];
      }
      for (j = i + 1; j < N && est[j] == 0; j++)
        ;
      if (j == N) break;
      if (j % 2 == 0) {
        cnt += j - x + abs(y - L[j]);
        x = j;
        y = L[j];
        i = j - 1;
      } else {
        cnt += abs(R[j] - y) + j - x;
        x = j;
        y = R[j];
        i = j - 1;
      }
    } else {
      if (est[i]) {
        cnt += y - L[i];
        x = i;
        y = L[i];
      }
      for (j = i + 1; j < N && est[j] == 0; j++)
        ;
      if (j == N) break;
      if (j % 2 == 0) {
        cnt += j - x + abs(y - L[j]);
        x = j;
        y = L[j];
        i = j - 1;
      } else {
        cnt += abs(R[j] - y) + j - x;
        x = j;
        y = R[j];
        i = j - 1;
      }
    }
  }
  printf("%d\n", cnt);
  return 0;
}
