#include <bits/stdc++.h>
using namespace std;
const int N = 200;
char mapa[N][N];
vector<pair<int, int> > arr;
int abs(int a) { return a < 0 ? -a : a; }
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", mapa[i]);
  for (int i = 0; i < n; ++i) {
    if (i % 2) {
      for (int j = m - 1; j >= 0; --j)
        if (mapa[i][j] == 'W') arr.push_back(make_pair(i, j));
    } else {
      for (int j = 0; j < m; ++j)
        if (mapa[i][j] == 'W') arr.push_back(make_pair(i, j));
    }
  }
  int i = 0, j = 0;
  int ans = 0;
  for (int k = 0; k < (int)arr.size();) {
    if (i == arr[k].first) {
      ans += abs(arr[k].second - j);
      j = arr[k].second;
    } else {
      ans += abs(arr[k].first - i);
      i = arr[k].first;
    }
    if (arr[k].first == i && arr[k].second == j) ++k;
  }
  printf("%d", ans);
  return 0;
}
