#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
template <typename T>
inline T sqr(const T& x) {
  return x * x;
}
template <class T>
inline void checkmin(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T& a, T b) {
  if (b > a) a = b;
}
const double eps = 1e-8;
inline int dcmp(double x) { return x < -eps ? -1 : x > eps; }
inline bool deq(double x, double y) { return dcmp(x - y) == 0; }
inline bool dleq(double x, double y) { return dcmp(x - y) <= 0; }
int first(string& s) { return find((s).begin(), (s).end(), 'W') - s.begin(); }
int last(string& s) {
  for (int i = s.length() - 1; i >= 0; i--)
    if (s[i] == 'W') return i;
  return -1;
}
int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  string line;
  int pos = 0, lrow = -1;
  for (int i = 0; i < n; i++) {
    cin >> line;
    if (!(find((line).begin(), (line).end(), 'W') != (line).end())) continue;
    if ((i & 1) == 0) {
      ans += i - lrow;
      lrow = i;
      int npos = min(pos, first(line));
      ans += abs(npos - pos);
      pos = npos;
      npos = last(line);
      ans += abs(npos - pos);
      pos = npos;
    } else {
      ans += i - lrow;
      lrow = i;
      int npos = max(pos, last(line));
      ans += abs(npos - pos);
      pos = npos;
      npos = first(line);
      ans += abs(npos - pos);
      pos = npos;
    }
  }
  if (ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}
