#include <bits/stdc++.h>
void print_array(int *a, int n) {
  printf("#");
  for (int i = 0; i < n; i++) printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
}
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3f3f3f3f;
char mp[200][200];
int l[200], r[200], cnt[200];
int n, m;
int solve() {
  int maxn = 0;
  for (int i = 0; i < n; ++i) {
    l[i] = INF, r[i] = -INF;
    for (int j = 0; j < m; ++j) {
      if (mp[i][j] == 'W') {
        maxn = max(maxn, i);
        cnt[i]++;
        l[i] = min(l[i], j);
        r[i] = max(r[i], j);
      }
    }
  }
  int cur = 0, ans = 0;
  for (int i = 0; i < maxn + 1; ++i) {
    int face = i % 2;
    int nextpos = cur;
    if (cnt[i]) {
      if (face == 0)
        nextpos = max(nextpos, r[i]);
      else
        nextpos = min(nextpos, l[i]);
    }
    if (i + 1 < n && cnt[i + 1]) {
      if (face == 0)
        nextpos = max(nextpos, r[i + 1]);
      else
        nextpos = min(nextpos, l[i + 1]);
    }
    ans += abs(nextpos - cur);
    cur = nextpos;
  }
  return ans + maxn;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", mp[i]);
  int ans = solve();
  printf("%d\n", ans);
  return 0;
}
