#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > x;
int ans = 0;
int get(int row, bool upper) {
  map<int, vector<int> >::iterator it = x.find(row);
  if (it == x.end()) return upper ? -1 : 1 << 30;
  return upper ? it->second.back() : it->second.front();
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> f;
  f.resize(n);
  int last = -1;
  for (int i = 0; i < n; i++) {
    cin >> f[i];
    for (int j = 0; j < m; j++)
      if (f[i][j] == 'W') x[i].push_back(j);
    if (x.find(i) != x.end()) last = i;
  }
  int r1, r2, r, C;
  C = 0;
  for (int i = 0; i <= last; i++) {
    if (i == last) {
      ans += abs(C - get(i, i % 2 == 0));
    } else if (i % 2 == 0) {
      r1 = get(i, true);
      r2 = get(i + 1, true);
      r = max(r1, r2);
      if (r != -1 && C <= r) {
        ans += r - C;
        C = r;
      }
      ++ans;
    } else {
      r1 = get(i, false);
      r2 = get(i + 1, false);
      r = min(r1, r2);
      if (r != (1 << 30) && C >= r) {
        ans += C - r;
        C = r;
      }
      ++ans;
    }
  }
  cout << ans;
}
