#include <bits/stdc++.h>
template <typename T>
T inline SQR(const T& a) {
  return a * a;
}
template <typename T>
T inline ABS(const T& a) {
  return a < 0 ? -a : a;
}
template <typename T>
T inline MIN(const T& a, const T& b) {
  if (a < b) return a;
  return b;
}
template <typename T>
T inline MAX(const T& a, const T& b) {
  if (a > b) return a;
  return b;
}
const double EPS = 1e-9;
inline int SGN(double a) {
  return ((a > EPS) ? (1) : ((a < -EPS) ? (-1) : (0)));
}
inline int CMP(double a, double b) { return SGN(a - b); }
using namespace std;
string gr[200];
int N, M;
int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> gr[i];
  int y = 0;
  int last = 0;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    int mn = 0x3F3F3F3F, mx = -1;
    for (int j = 0; j < M; ++j) {
      if (gr[i][j] == 'W') {
        mn = MIN(mn, j);
        mx = MAX(mx, j);
      }
    }
    if (mx == -1) continue;
    last = i;
    if (i & 1) {
      if (mx > y) {
        ans += mx - y;
        y = mx;
      }
      ans += y - mx;
      ans += mx - mn;
      y = mn;
    } else {
      if (mn < y) {
        ans += y - mn;
        y = mn;
      }
      ans += mn - y;
      ans += mx - mn;
      y = mx;
    }
  }
  ans += last;
  cout << ans << "\n";
  return 0;
}
