#include <bits/stdc++.h>
using namespace std;
int n, m;
char grid[155][155];
int memo[155][155][2];
enum dir { R, L };
int solve(int i, int j, dir d) {
  if (i == n) return 0;
  int &res = memo[i][j][d];
  int idx = -1;
  if (res != -1) return res;
  res = (1 << 20);
  if (d == R) {
    for (int k = 0; k < j; ++k)
      if (grid[i][k] == 'W') {
        return res;
      }
    idx = j;
    for (int k = j; k < m; ++k)
      if (grid[i][k] == 'W') {
        idx = k;
      }
    for (int k = idx; k < m; ++k) {
      res = min(res, solve(i + 1, k, L) + k - j);
    }
  } else {
    for (int k = j + 1; k < m; ++k)
      if (grid[i][k] == 'W') {
        return res;
      }
    idx = j;
    for (int k = j; k >= 0; --k)
      if (grid[i][k] == 'W') {
        idx = k;
      }
    for (int k = idx; k >= 0; --k) {
      res = min(res, solve(i + 1, k, R) + j - k);
    }
  }
  return res;
}
int main() {
  memset(memo, -1, sizeof memo);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%s", grid[i]);
  for (int i = n - 1; i >= 0; --i) {
    for (int j = 0; j < m; ++j)
      if (grid[i][j] == 'W') {
        n = i + 1;
        goto start;
      }
  }
  n = 1;
start:;
  printf("%d\n", solve(0, 0, R) + n - 1);
  return 0;
}
