#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e17 + 7;
const long long N = 200;
long long n, m, mn[N], mx[N], rm = 0;
string s[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (long long i = 0; i < (n + 1); ++i) mn[i] = m - 1, mx[i] = 0;
  for (long long i = 0; i < (n); ++i) cin >> s[i];
  s[0][0] = 'W';
  for (long long i = 0; i < (n); ++i)
    for (long long j = 0; j < (m); ++j)
      if (s[i][j] == 'W')
        mn[i] = min(mn[i], j), mx[i] = max(mx[i], j), rm = max(rm, i);
  long long cnt = 0, prv = 0, nx = 0;
  for (long long i = 0; i < (n); ++i) {
    if (i % 2 == 0) {
      nx = max(mx[i], mx[i + 1]);
      nx = max(prv, nx);
      cnt += nx - prv;
    } else {
      nx = min(mn[i], mn[i + 1]);
      nx = min(nx, prv);
      cnt += prv - nx;
    }
    prv = nx;
    if (i == rm) break;
    cnt++;
  }
  cout << cnt << endl;
}
