#include <bits/stdc++.h>
using namespace std;
const int N = 151;
int m, n;
char gd[N][N];
inline int fab(int x) { return x > 0 ? x : -x; }
int main() {
  while (scanf("%d%d", &m, &n) != -1) {
    for (int i = 0; i < m; i++) scanf("%s", gd[i]);
    int ans = 0, x = 0, y = 0;
    for (int i = 0; i < m; i++)
      for (int j = (i & 1 ? n - 1 : 0); 0 <= j && j < n; j += (i & 1 ? -1 : 1))
        if (gd[i][j] == 'W') {
          ans += fab(i - x) + fab(j - y);
          x = i;
          y = j;
        }
    printf("%d\n", ans);
  }
  return 0;
}
