#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<string> garden(n);
  copy_n(istream_iterator<string>(cin), n, garden.begin());
  vector<pair<int, int> > weeds;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int new_j = j;
      if (i % 2 == 1) new_j = m - 1 - j;
      if (garden[i][new_j] == 'W') weeds.push_back(make_pair(i, new_j));
    }
  }
  int r = 0, c = 0;
  int ans = 0;
  for (int i = 0; i < weeds.size(); ++i) {
    int nr = weeds[i].first, nc = weeds[i].second;
    ans += abs(nc - c);
    ans += abs(nr - r);
    r = nr;
    c = nc;
  }
  cout << ans << endl;
  return 0;
}
