#include <bits/stdc++.h>
using namespace std;
int main() {
  int test, n, m, first[1000], last[1000], last_trash, y = 1, cur = 1, ANS = 0;
  string A[1000];
  bool kt = true;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> A[i];
    for (int j = 1; j <= m; ++j)
      if (A[i][j - 1] == 'W') {
        if (!last[i]) first[i] = j;
        last[i] = j;
      }
    if (first[i] && last[i]) {
      kt = false;
      last_trash = i;
    }
  }
  if (kt) {
    cout << '0';
    return 0;
  }
  while (cur <= last_trash) {
    if (cur % 2 != 0) {
      if (last[cur]) {
        ANS += abs(y - last[cur]);
        y = last[cur];
      }
      if (last[cur + 1] && last[cur + 1] > y && cur < last_trash) {
        ANS += last[cur + 1] - y;
        y = last[cur + 1];
      }
    } else {
      if (first[cur]) {
        ANS += abs(y - first[cur]);
        y = first[cur];
      }
      if (first[cur + 1] && first[cur + 1] < y && cur < last_trash) {
        ANS += y - first[cur + 1];
        y = first[cur + 1];
      }
    }
    ++ANS;
    ++cur;
  }
  cout << ANS - 1;
}
