#include <bits/stdc++.h>
using namespace std;
char g[200][200];
int n, m;
int abs(int u) {
  if (u > 0) return u;
  return -u;
}
int cal1(int a, int b, int pos) {
  if (a == m + 1 && b == m + 1) return pos;
  if (b == m + 1) return a;
  if (a == m + 1) return b;
  return min(a, b);
}
int cal2(int a, int b, int pos) {
  if (a == -1 && b == -1) return pos;
  if (b == -1) return a;
  if (a == -1) return b;
  return max(a, b);
}
int main() {
  int i, j, l[200], r[200], pos, tp, line, cnt, res;
  while (scanf("%d%d", &n, &m) != EOF) {
    getchar();
    for (i = 0; i < n; ++i) gets(g[i]);
    for (i = 0; i < n; ++i) {
      l[i] = m + 1;
      r[i] = -1;
      for (j = 0; j < m; ++j) {
        if (g[i][j] == 'W') {
          l[i] = min(l[i], j);
          r[i] = max(r[i], j);
        }
      }
    }
    pos = 0;
    cnt = 0;
    line = 0;
    for (i = 0; i < n - 1; ++i) {
      if (l[i] != m + 1) line = i;
      if (i & 1) {
        tp = cal1(l[i], l[i + 1], pos);
        cnt += (abs(tp - pos));
        cnt++;
        pos = tp;
      } else {
        tp = cal2(r[i], r[i + 1], pos);
        cnt += (abs(tp - pos));
        cnt++;
        pos = tp;
      }
    }
    if (l[n - 1] == m + 1) {
      cnt -= (n - 1 - line);
    } else {
      if ((n - 1) & 1) {
        tp = l[i];
        cnt += (abs(tp - pos));
      } else {
        tp = r[i];
        cnt += (abs(tp - pos));
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
