#include <bits/stdc++.h>
using namespace std;
int m[152][2];
int compute(char a[][152], int r, int c) {
  memset(m, -1, sizeof m);
  int i, j;
  for (i = 0; i < r; ++i) {
    for (j = 0; j < c; ++j) {
      if (a[i][j] == 'W') {
        if (m[i][0] == -1) m[i][0] = j;
        m[i][1] = j;
      }
    }
  }
  int ans = 0, x = 0, y = 0;
  for (i = 0; i < r; ++i) {
    if ((i & 1) == 1 && m[i][0] != -1) {
      ans += abs(y - m[i][1]) + i - x + m[i][1] - m[i][0];
      x = i;
      y = m[i][0];
    } else if ((i & 1) == 0 && m[i][0] != -1) {
      ans += abs(y - m[i][0]) + i - x + m[i][1] - m[i][0];
      x = i;
      y = m[i][1];
    }
  }
  return ans;
}
int main() {
  int i, j, r, c, ans;
  scanf("%d", &r);
  scanf("%d", &c);
  char a[152][152], b[152][152];
  for (i = 0; i < r; ++i) scanf("%s", a[i]);
  ans = compute(a, r, c);
  printf("%d\n", ans);
  return 0;
}
