#include <bits/stdc++.h>
using namespace std;
int y, x, l[155], r[155], ex[2], num[155], ey;
int f(int x, int y, int d) {
  if (y == ey) {
    int ans = x - ex[d];
    if (ans < 0) ans = -ans;
    return ans;
  }
  int ty = y + 1;
  while ((num[ty]) == 0) ty++;
  int res;
  if (d == 0) {
    if ((ty - y) % 2 == 1)
      return ty - y + max(r[y], r[ty]) - x + f(max(r[y], r[ty]), ty, 1);
    else
      return r[y] - x + ty - y + abs(r[y] - l[ty]) + f(l[ty], ty, 0);
  } else {
    if ((ty - y + 1) % 2 == 0)
      return ty - y + x - min(l[y], l[ty]) + f(min(l[y], l[ty]), ty, 0);
    else
      return x - l[y] + ty - y + abs(r[ty] - l[y]) + f(r[ty], ty, 1);
  }
}
int main() {
  char c[155][155];
  cin >> y >> x;
  for (int i = 0; i < y; i++) {
    l[i] = x;
    r[i] = 0;
  }
  for (int j = 0; j < y; j++)
    for (int i = 0; i < x; i++) {
      cin >> c[i][j];
      if (c[i][j] == 'W') {
        num[j] = 1;
        r[j] = i;
        ex[0] = i;
        ey = j;
      }
    }
  for (int j = 0; j < y; j++)
    for (int i = x - 1; i >= 0; i--) {
      if (c[i][j] == 'W') {
        l[j] = i;
        ex[1] = i;
      }
    }
  cout << f(0, 0, 0) << endl;
}
