#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int pole[150][2];
  vector<pair<int, int>> v;
  cin >> n >> m;
  string s;
  int x1, x2;
  int lastrowtoclear = -1;
  for (int i = 0; i < n; i++) {
    cin >> s;
    pole[i][0] = s.find_first_of("W");
    pole[i][1] = s.find_last_of("W");
    if (pole[i][0] >= 0) lastrowtoclear = i;
  }
  long sum = 0;
  int startpos = 0;
  int pos;
  for (int i = 0; i <= lastrowtoclear; i++) {
    pos = startpos;
    if (i % 2 == 0) {
      if (pole[i][1] > pos) pos = pole[i][1];
      if (i < lastrowtoclear && pole[i + 1][1] > pos) pos = pole[i + 1][1];
      sum += pos - startpos;
    } else {
      if (pole[i][0] >= 0 && pole[i][0] < pos) pos = pole[i][0];
      if (i < lastrowtoclear && pole[i + 1][0] >= 0 && pole[i + 1][0] < pos)
        pos = pole[i + 1][0];
      sum += startpos - pos;
    }
    startpos = pos;
  }
  if (lastrowtoclear > 0) sum += lastrowtoclear;
  cout << sum;
  return 0;
}
