#include <bits/stdc++.h>
using namespace std;
const int maxn = 250;
int l[maxn], r[maxn];
char g[maxn][maxn];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", g[i] + 1);
  for (int i = 1, j; i <= n; i++) {
    for (j = 1; j <= m; j++)
      if (g[i][j] == 'W') break;
    l[i] = j;
    for (j = m; j >= 1; j--)
      if (g[i][j] == 'W') break;
    r[i] = j;
  }
  while (r[n] == 0) n--;
  int ans = 0;
  l[n + 1] = m + 1;
  r[n + 1] = 0;
  int x = 1;
  for (int i = 1; i <= n; i++) {
    if (i % 2) {
      for (; x < r[i]; x++, ans++)
        ;
      for (; x < r[i + 1]; x++, ans++)
        ;
    } else {
      for (; x > l[i]; x--, ans++)
        ;
      for (; x > l[i + 1]; x--, ans++)
        ;
    }
    if (i != n) ans++;
  }
  printf("%d\n", ans);
  return 0;
}
