#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
map<long long, vector<long long>> m;
int main() {
  long long n, m, ans = 0, q = 0;
  cin >> n >> m;
  string s[n];
  vector<pair<long long, long long>> v;
  for (long long i = 0; i < n; i++) {
    cin >> s[i];
    v.push_back({INT_MAX, INT_MIN});
  }
  for (long long i = 0; i < n; i++) {
    long long f = 1;
    for (long long j = 0; j < m; j++) {
      if (f == 1 && s[i][j] == 'W') {
        v[i].first = j;
        v[i].second = j;
        f = 0;
        q = i;
      } else if (f == 0 && s[i][j] == 'W') {
        v[i].second = j;
      }
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    long long x;
    if (i % 2 == 0) {
      x = max(v[i].second, v[i + 1].second);
      v[i].second = x, v[i + 1].second = x;
    } else {
      x = min(v[i].first, v[i + 1].first);
      v[i].first = x, v[i + 1].first = x;
    }
  }
  long long p = 0;
  for (long long i = 0; i < n; i++) {
    if (i % 2 == 0) {
      if (v[i].second != INT_MIN) {
        ans += abs(v[i].second - p);
        p = v[i].second;
      }
    } else {
      if (v[i].first != INT_MAX) {
        ans += abs(p - v[i].first);
        p = v[i].first;
      }
    }
  }
  ans += q;
  cout << ans << endl;
}
