#include <bits/stdc++.h>
using namespace std;
int n, m, p[151][2], l = -1, ans, x;
char s;
int main() {
  memset(p, -1, sizeof p);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> s;
      if (s == 'W') {
        l = i;
        p[i][1] = j;
        if (p[i][0] == -1) p[i][0] = j;
      }
    }
    ans += p[i][1] - p[i][0];
  }
  ans += max(0, l);
  for (int i = 0; i <= l; i++) {
    if (p[i][0] == -1) continue;
    if (i % 2) {
      ans += abs(x - p[i][1]);
      x = p[i][0];
    } else {
      ans += abs(x - p[i][0]);
      x = p[i][1];
    }
  }
  cout << ans;
  return 0;
}
