#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void ckmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void ckmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
int main() {
  int n, m, ptr = 0, ipt = 0, pt = 0, ct = 0;
  cin >> n >> m;
  string s[n];
  for (int i = 0; i < (n); ++i) {
    cin >> s[i];
    for (int j = 0; j < (m); ++j)
      if (s[i][j] == 'W') ipt = i;
  }
  int k = 0;
  for (int i = 0; i < (n); ++i) {
    ptr = pt = k;
    if (i % 2 == 0) {
      if (i == n - 1) {
        for (int j = 0; j < (m); ++j)
          if (s[i][j] == 'W') pt = j;
        ct += pt - k;
      } else {
        for (int j = 0; j < (m); ++j)
          if (s[i + 1][j] == 'W') ptr = j;
        for (int j = 0; j < (m); ++j)
          if (s[i][j] == 'W') pt = j;
        for (int j = 0; j < (m); ++j)
          if (j >= ptr && j >= pt) {
            ct += j - k;
            break;
          }
        k = max(ptr, pt);
      }
    } else {
      if (i == n - 1) {
        for (int j = m - 1; j >= 0; --j)
          if (s[i][j] == 'W') pt = j;
        ct += k - pt;
      } else {
        for (int j = m - 1; j >= 0; --j)
          if (s[i + 1][j] == 'W') ptr = j;
        for (int j = m - 1; j >= 0; --j)
          if (s[i][j] == 'W') pt = j;
        for (int j = m - 1; j >= 0; --j)
          if (j <= ptr && j <= pt) {
            ct += k - j;
            break;
          }
        k = min(ptr, pt);
      }
    }
  }
  cout << ct + ipt;
  return 0;
}
