#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[152];
int r[152];
vector<pair<string, int> > vs;
int maxR;
int main() {
  cout << setprecision(9);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    bool ok = false;
    for (int j = 0; j < m; j++) {
      if (s[j] == 'W') {
        ok = true;
        maxR = i;
      }
    }
    if (ok || (i == 0)) vs.push_back(make_pair(s, i % 2));
  }
  for (int i = 0; i < vs.size(); i++) {
    l[i] = 400;
    r[i] = 0;
    string s = vs[i].first;
    for (int j = 0; j < m; j++) {
      if (s[j] == 'W') {
        l[i] = min(l[i], j);
        r[i] = max(r[i], j);
      }
    }
  }
  l[0] = 0;
  int ret = 0;
  for (int i = 0; i < vs.size(); i++) {
    ret += abs(l[i] - r[i]);
  }
  for (int i = 0; i < (int)vs.size() - 1; i++) {
    int par1 = vs[i].second;
    int par2 = vs[i + 1].second;
    if (par1 == 0 && par2 == 1) ret += abs(r[i] - r[i + 1]);
    if (par1 == 0 && par2 == 0) ret += abs(r[i] - l[i + 1]);
    if (par1 == 1 && par2 == 0) ret += abs(l[i] - l[i + 1]);
    if (par1 == 1 && par2 == 1) ret += abs(l[i] - r[i + 1]);
  }
  ret += maxR;
  cout << ret << endl;
  return 0;
}
