#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int64_t lol;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  int64_t testc = 1;
  while (testc--) {
    long long n, m;
    cin >> n >> m;
    vector<long long> v[155];
    for (long long i = 1; i <= n; i++) {
      string x;
      cin >> x;
      for (long long ii = 1; ii <= m; ii++) {
        if (x[ii - 1] == 'W') {
          v[i].push_back(ii);
        }
      }
      if (i % 2 == 0) {
        reverse(v[i].begin(), v[i].end());
      }
    }
    long long out = 0;
    vector<pair<long long, long long>> opt;
    for (long long i = 1; i <= n; i++) {
      for (long long ii = 0; ii < v[i].size(); ii++) {
        opt.push_back(make_pair(i, v[i][ii]));
      }
    }
    for (long long i = 1; i < opt.size(); i++) {
      out += abs(opt[i].first - opt[i - 1].first);
      out += abs(opt[i].second - opt[i - 1].second);
    }
    if (!opt.size()) {
      return cout << 0, 0;
    }
    out += ((opt[0].first - 1) + (opt[0].second - 1));
    cout << out << "\n";
  }
  return EXIT_SUCCESS;
}
