#include <bits/stdc++.h>
using namespace std;
inline bool iseq(double x, double y) {
  if (fabs(x - y) < 1e-8) return true;
  return false;
}
template <typename T>
inline T hpt(T x1, T y1, T x2, T y2) {
  return hypot(x1 - x2, y1 - y2);
}
template <typename T>
inline T gcd(T a, T b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
template <typename T>
inline void extended_euclid(T a, T b, T &x, T &y) {
  if (a % b == 0)
    x = 0, y = 1;
  else {
    extended_euclid(b, a % b, x, y);
    T temp = x;
    x = y;
    y = -y * (a / b) + temp;
  }
}
template <typename T>
inline T bigmod(T b, T p, T m) {
  if (!p)
    return 1;
  else if (!(p % 2)) {
    T x = bigmod(b, p / 2, m);
    return x * x;
  } else
    return ((b % m) * bigmod(b, p - 1, m)) % m;
}
int sum, r, n, N, R, C;
int ok[155][155][3];
char F[155][155];
int dp[155][155][3];
void build() {
  int i, j, k;
  for (i = (0); i < (R); i++)
    for (j = (0); j < (C); j++) {
      ok[i][j][0] = (1 << 20);
      ok[i][j][1] = -1;
    }
  for (i = (0); i < (R); i++)
    if (F[i][0] == 'W') ok[i][0][0] = 0;
  for (i = (0); i < (R); i++)
    for (j = (1); j < (C); j++) {
      if (F[i][j] == 'W') ok[i][j][0] = j;
      ok[i][j][0] = min(ok[i][j][0], ok[i][j - 1][0]);
    }
  for (i = (0); i < (R); i++)
    if (F[i][C - 1] == 'W') ok[i][C - 1][1] = C - 1;
  for (i = (0); i < (R); i++)
    for (j = C - 2; j >= 0; j--) {
      if (F[i][j] == 'W') ok[i][j][1] = j;
      ok[i][j][1] = max(ok[i][j][1], ok[i][j + 1][1]);
    }
}
bool niche(int x, int y, int dir) {
  if (x + 1 == R) return true;
  int pos = ok[x + 1][y][1 - dir];
  if (dir == 0) {
    if (pos > y) return false;
  } else {
    if (pos < y) return false;
  }
  return true;
}
int calc(int x, int y, int dir) {
  if (y < 0 || y >= C) return (1 << 20);
  int &ret = dp[x][y][dir];
  if (ret > -1) return ret;
  if (x == R) {
    return -1;
  }
  ret = 0;
  int pos = ok[x][y][1 - dir];
  int ra = (1 << 20), rb = (1 << 20), rc = (1 << 20);
  if (dir == 0) {
    if (pos > y)
      ret += (pos - y);
    else
      pos = y;
    if (niche(x, pos, dir) == true) {
      ra = calc(x + 1, pos, 1 - dir) + 1;
      rb = calc(x, pos + 1, dir) + 1;
      ret = ret + min(ra, rb);
    } else {
      ret += calc(x, pos + 1, dir) + 1;
    }
  } else {
    if (pos < y)
      ret += (y - pos);
    else
      pos = y;
    if (niche(x, pos, dir) == true) {
      ra = calc(x + 1, pos, 1 - dir) + 1;
      rb = calc(x, pos - 1, dir) + 1;
      ret = ret + min(ra, rb);
    } else {
      ret += calc(x, pos - 1, dir) + 1;
    }
  }
  return ret;
}
void Test() {
  int i, j, k;
  for (i = R - 1; i > 0; i--) {
    bool all = false;
    for (j = 0; j < C; j++)
      if (F[i][j] == 'W') all = true;
    if (all) return;
    R = i;
  }
}
int main() {
  int i, j, k;
  while (scanf("%d%d", &R, &C) == 2) {
    memset(dp, -1, sizeof(dp));
    for (i = (0); i < (R); i++) scanf("%s", F[i]);
    Test();
    build();
    int ans = calc(0, 0, 0);
    cout << ans << endl;
  }
  return 0;
}
