#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y;
  cin >> x >> y;
  int bottom = 0;
  vector<int> mins;
  vector<int> maxs;
  for (int i = 0; i < x; ++i) {
    string line;
    int curmin = 200;
    int curmax = -1;
    cin >> line;
    for (int j = 0; j < y; ++j) {
      if (line[j] == 'W') {
        if (i > bottom) bottom = i;
        if (j > curmax) {
          curmax = j;
        }
        if (curmin == 200) {
          curmin = j;
        }
      }
    }
    mins.push_back(curmin);
    maxs.push_back(curmax);
  }
  int curPos = 0;
  int sum = 0;
  for (int i = 0; i <= bottom; ++i) {
    if (i % 2 == 0) {
      int curmax = maxs[i];
      if (i < x - 1) {
        curmax = max(curmax, maxs[i + 1]);
      }
      if (curmax == -1) {
        continue;
      }
      sum += abs(curmax - curPos);
      curPos = curmax;
    }
    if (i % 2 == 1) {
      int curmin = mins[i];
      if (i < x - 1) {
        curmin = min(curmin, mins[i + 1]);
      }
      if (curmin == 200) {
        continue;
      }
      sum += abs(curPos - curmin);
      curPos = curmin;
    }
  }
  cout << sum + bottom << endl;
}
