#include <bits/stdc++.h>
char bo[155][155];
int dp[155][2];
int num[155];
int main() {
  int n, m, i, j;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%s", bo[i] + 1);
  }
  memset(num, 0, sizeof(num));
  memset(dp, 0, sizeof(dp));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (bo[i][j] == 'W') {
        dp[i][0] = j, num[i] = 1;
        break;
      }
    }
    for (j = m; j >= 1; j--) {
      if (bo[i][j] == 'W') {
        dp[i][1] = j;
        break;
      }
    }
  }
  int po = 1, now = 1, ans = 0, tmp;
  i = 2;
  if (num[1]) {
    now = dp[1][1];
    ans += dp[1][1] - 1;
  }
  while (i <= n) {
    while (!num[i] && i <= n) i++;
    if (i > n) break;
    if (i % 2) {
      ans += i - po + abs(now - dp[i][0]);
      po = i;
      ans += dp[i][1] - dp[i][0];
      now = dp[i][1];
    } else {
      ans += i - po + abs(now - dp[i][1]);
      po = i;
      ans += dp[i][1] - dp[i][0];
      now = dp[i][0];
    }
    i++;
  }
  printf("%d\n", ans);
  return 0;
}
