#include <bits/stdc++.h>
using namespace std;
inline void read(register int *n) {
  register char c;
  *n = 0;
  do {
    c = getchar();
  } while (c < '0' || c > '9');
  do {
    *n = c - '0' + *n * 10;
    c = getchar();
  } while (c >= '0' && c <= '9');
}
int main() {
  int x = 0, tot = 0;
  int n, m;
  cin >> n >> m;
  vector<string> V(n);
  for (register int i = (0); i < (int)(n); ++i) cin >> V[i];
  while (((int)(V).size())) {
    if (V.back().find("W") == string::npos)
      V.pop_back();
    else
      break;
  }
  if (V.empty()) {
    cout << 0 << "\n";
    return 0;
  }
  for (register int i = (0); i < (int)(((int)(V).size())); ++i) {
    if (i) tot++;
    string row = V[i];
    int first = -1, last = -1;
    for (register int j = (0); j < (int)(m); ++j)
      if (row[j] == 'W') {
        if (first == -1) first = j;
        last = j;
      }
    if (first == -1) continue;
    if (i % 2) {
      tot += abs(x - last) + last - first;
      x = first;
    } else {
      tot += abs(x - first) + last - first;
      x = last;
    }
  }
  cout << tot << "\n";
  return 0;
}
