#include <bits/stdc++.h>
using namespace std;
int lef[222], righ[222];
char mp[222][222];
int h[222];
int N, M;
int main() {
  while (~scanf("%d%d", &N, &M)) {
    bool flag = false;
    int wt = 0;
    memset(h, 0, sizeof(h));
    for (int i = 0; i < N; i++) {
      scanf(" %s", mp[i]);
      for (int j = 0; j < M; j++) {
        if (mp[i][j] == 'W') {
          wt++;
          h[i]++;
        }
      }
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        if (mp[i][j] == 'W') {
          flag = true;
          lef[i] = j;
          break;
        }
      }
      for (int j = M - 1; j >= 0; j--) {
        if (mp[i][j] == 'W') {
          righ[i] = j;
          break;
        }
      }
    }
    if (!flag)
      printf("0\n");
    else if (mp[0][0] == 'W' && wt == 1)
      printf("0\n");
    else {
      int cnt = 0, s = 0, t, fin = 0;
      for (int i = 0; i < N - 1; i++) {
        if (i % 2 == 0) {
          if (h[i + 1] == 0) {
            t = righ[i];
            lef[i + 1] = righ[i + 1] = t;
          } else {
            t = (righ[i] > righ[i + 1] ? righ[i] : righ[i + 1]);
          }
          cnt += t - s;
          fin += h[i];
          if (fin == wt) break;
          cnt++;
          s = t;
        } else {
          if (h[i + 1] == 0) {
            t = lef[i];
            lef[i + 1] = righ[i + 1] = t;
          } else {
            t = (lef[i] < lef[i + 1] ? lef[i] : lef[i + 1]);
          }
          cnt += s - t;
          fin += h[i];
          if (fin == wt) break;
          cnt++;
          s = t;
        }
      }
      if (fin != wt) {
        if ((N - 1) % 2 == 0)
          cnt += righ[N - 1] - s;
        else
          cnt += s - lef[N - 1];
      }
      printf("%d\n", cnt);
    }
  }
  return 0;
}
