#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  char mp[151][151];
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> mp[i];
  int lf[151];
  int rf[151];
  int nw[151] = {0};
  int wd = 0;
  for (int i = 0; i < 151; i++) {
    lf[i] = 300;
    rf[i] = -1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mp[i][j] == 'W') {
        lf[i] = min(lf[i], j);
        rf[i] = max(rf[i], j);
        nw[i]++;
        wd++;
      }
    }
  }
  int ans = -1;
  int pos = 0;
  int h = 0;
  int dir = 1;
  while (wd) {
    ans++;
    if (dir) {
      int tg = max(pos, max(rf[h], rf[h + 1]));
      ans += tg - pos;
      pos = tg;
    } else {
      int tg = min(pos, min(lf[h], lf[h + 1]));
      ans += pos - tg;
      pos = tg;
    }
    wd -= nw[h];
    dir ^= 1;
    h++;
  }
  cout << max(0, ans) << endl;
  return 0;
}
