#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int diri[4] = {-1, 0, 1, 0};
const int dirj[4] = {0, 1, 0, -1};
int main() {
  int n, m;
  cin >> n >> m;
  int f = 0;
  vector<int> esq(n, -1), dre(n, -1);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      if (c == 'W') {
        if (esq[i] == -1)
          esq[i] = dre[i] = j;
        else
          dre[i] = j;
        f = i;
      }
    }
  int res = 0;
  int j = 0;
  for (int i = 0; i <= f; ++i) {
    if (i % 2 == 0) {
      if (dre[i] != -1 and j < dre[i]) {
        res += dre[i] - j;
        j = dre[i];
      }
      if (i + 1 < n and dre[i + 1] != -1 and j < dre[i + 1]) {
        res += dre[i + 1] - j;
        j = dre[i + 1];
      }
    } else {
      if (esq[i] != -1 and esq[i] < j) {
        res += j - esq[i];
        j = esq[i];
      }
      if (i + 1 < n and esq[i + 1] != -1 and esq[i + 1] < j) {
        res += j - esq[i + 1];
        j = esq[i + 1];
      }
    }
    if (i < f) ++res;
  }
  cout << res << endl;
}
