#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
void read(T &res) {
  bool flag = false;
  char ch;
  while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
  for (res = ch - 48; isdigit(ch = getchar());
       res = (res << 1) + (res << 3) + ch - 48)
    ;
  flag && (res = -res);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long qp(long long a, long long b, long long mod) {
  long long ans = 1;
  if (b == 0) {
    return ans % mod;
  }
  while (b) {
    if (b % 2 == 1) {
      b--;
      ans = ans * a % mod;
    }
    a = a * a % mod;
    b = b / 2;
  }
  return ans % mod;
}
long long qpn(long long a, long long b, long long p) {
  long long ans = 1;
  a %= p;
  while (b) {
    if (b & 1) {
      ans = (ans * a) % p;
      --b;
    }
    a = (a * a) % p;
    b >>= 1;
  }
  return ans % p;
}
char s[500][500];
signed main() {
  long long n, m;
  read(n);
  read(m);
  for (long long i = 1; i <= n; i++) {
    scanf("%s", s[i] + 1);
  }
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s[i][j] == 'W') {
        sum++;
      }
    }
  }
  long long d = 1;
  long long ans = 0;
  long long y = 0;
  for (long long i = 1; i <= n; i++) {
    if (sum <= 0) {
      break;
    }
    long long ma = -1;
    for (long long j = 1; j <= m; j++) {
      if (s[i][j] == 'W') {
        if (d == 1) {
          ma = j;
        } else {
          if (ma == -1) {
            ma = j;
          }
        }
      }
      if (s[i + 1][j] == 'W') {
        if (d == 1) {
          ma = j;
        } else {
          if (ma == -1) {
            ma = j;
          }
        }
      }
    }
    if (ma == -1) {
      ans = ans + 1;
      d = (d + 1) % 2;
      continue;
    } else {
      d = (d + 1) % 2;
      ans = ans + abs(y - ma);
      for (long long z = 1; z <= m; z++) {
        if (s[i][z] == 'W') sum--;
      }
      y = ma;
      if (i != n && sum > 0) ans++;
    }
  }
  if (ans >= 1) {
    ans--;
  }
  printf("%lld\n", ans);
}
