#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int INFLL = 1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-14;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
const int MAX_N = 256;
int n, m;
int le[MAX_N], ri[MAX_N];
char s[MAX_N][MAX_N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (0); i < (int)(n); i++) scanf("%s", s[i]);
  int last = 0;
  for (int i = (0); i < (int)(n); i++) {
    le[i] = INF;
    ri[i] = 0;
    for (int j = (0); j < (int)(m); j++)
      if (s[i][j] == 'W') {
        chmin(le[i], j);
        chmax(ri[i], j);
        last = i;
      }
  }
  int p = 0;
  int ans = 0;
  for (int i = (0); i < (int)(n); i++) {
    if (i % 2 == 0) {
      int np = min(p, le[i]);
      ans += p - np;
      int nnp = max(np, ri[i]);
      ans += nnp - np;
      p = nnp;
    } else {
      int np = max(p, ri[i]);
      ans += np - p;
      int nnp = min(np, le[i]);
      ans += np - nnp;
      p = nnp;
    }
  }
  cout << ans + last << endl;
  return 0;
}
