#include <bits/stdc++.h>
using namespace std;
template <class Ty, class Tx>
Ty cast(const Tx &x) {
  Ty y;
  stringstream ss("");
  ss << x;
  ss.seekg(0);
  ss >> y;
  return y;
}
int n, m;
char g[155][155];
int memo[155][155];
bool seen[155][155];
int doit(int i, int j) {
  if (i >= n) return -1;
  int &ret = memo[i][j];
  if (seen[i][j]) return ret;
  seen[i][j] = true;
  int k, d, maxk;
  ret = 1 << 20;
  d = 1;
  if (i % 2) d *= -1;
  for (k = j - d; k >= 0 && k < m; k -= d)
    if (g[i][k] == 'W') return ret;
  maxk = j;
  for (k = j; k >= 0 && k < m; k += d) {
    if (g[i][k] == 'W') maxk = k;
  }
  for (k = maxk; k >= 0 && k < m; k += d) {
    ret = min(ret, abs(k - j) + 1 + doit(i + 1, k));
  }
  return ret;
}
int main() {
  int i, j, ret, r, k;
  cin >> n >> m;
  for ((i) = 0; (i) < (n); (i)++)
    for ((j) = 0; (j) < (m); (j)++) cin >> g[i][j];
  memset((seen), (0), sizeof(seen));
  for ((i) = (n)-1; (i) >= 0; (i)--) {
    for ((j) = 0; (j) < (m); (j)++)
      if (g[i][j] == 'W') break;
    if (j < m) break;
  }
  if (i < 0) i = 0;
  cout << doit(0, 0) - (n - 1 - i) << endl;
  return 0;
}
