#include <bits/stdc++.h>
using namespace std;
int best[155][155];
bool flag[155][155];
int n, m;
char grid[155][155];
int maxl[155], maxr[155];
int solve(int i, int j, bool f) {
  if (i == n) return -1;
  if (maxl[i] != -1 && ((j < maxr[i] && f) || (j > maxl[i] && (!f))))
    return 1 << 20;
  if (flag[i][j]) return best[i][j];
  flag[i][j] = 1;
  int c, c2;
  int ret = 1 << 20;
  if (!f) {
    int start = maxr[i];
    if (start == -1) start = j;
    for (c = start; c < m; c++) ret = min(ret, c - j + 1 + solve(i + 1, c, !f));
  } else {
    int start = maxl[i];
    if (start == -1) start = j;
    for (c = start; c >= 0; c--)
      ret = min(ret, j - c + 1 + solve(i + 1, c, !f));
  }
  return best[i][j] = ret;
}
int main() {
  FILE *in = stdin;
  int c, c2;
  fscanf(in, "%d%d", &n, &m);
  for (c = 0; c < n; c++) {
    fscanf(in, "%s", grid[c]);
    maxl[c] = -1;
    maxr[c] = -1;
    for (c2 = m - 1; c2 >= 0; c2--)
      if (grid[c][c2] == 'W') maxl[c] = c2;
    for (c2 = 0; c2 < m; c2++)
      if (grid[c][c2] == 'W') maxr[c] = c2;
  }
  for (c = n - 1; c >= 0; c--) {
    for (c2 = 0; c2 < m; c2++)
      if (grid[c][c2] == 'W') break;
    if (c2 < m) break;
    n--;
  }
  memset(flag, 0, sizeof(flag));
  int ret = solve(0, 0, 0);
  printf("%d\n", max(ret, 0));
  return 0;
}
