#include <bits/stdc++.h>
using namespace std;
int CC;
struct str {
  int L, P;
  char C[15];
  bool operator<(const str& S) const {
    if (P > S.P) return true;
    if (P < S.P) return false;
    return (strcmp(C, S.C) < 0);
  }
};
str G[101];
int GetPOS(char* A) {
  for (int p = (1); p <= (CC); p += (1))
    if (strcmp(A, G[p].C) == 0) return p;
  CC++;
  strcpy(G[CC].C, A);
  G[CC].L = strlen(A);
  G[CC].P = 0;
  return CC;
}
int MOD(int p) { return p > 0 ? p : -1 * p; }
bool InRange(int p, int l, int u) { return p >= l && p <= u; }
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int MCM(int a, int b) { return a * b / GCD(a, b); }
int MIN2N(int a, int b) {
  if (a <= b) return a;
  return b;
}
int MAX2N(int a, int b) {
  if (a >= b) return a;
  return b;
}
int MIN3N(int a, int b, int c) {
  if (a <= b && a <= c) return a;
  if (b <= c) return b;
  return c;
}
int MAX3N(int a, int b, int c) {
  if (a >= b && a >= c) return a;
  if (b >= c) return b;
  return c;
}
bool* m_criba;
void criba(bool*& m, int tam) {
  m = new bool[tam + 1];
  m[0] = m[1] = false;
  for (int i = 2; i <= tam; ++i) m[i] = true;
  for (int i = 2; i * i <= tam; ++i)
    if (m[i])
      for (int h = 2; i * h <= tam; ++h) m[i * h] = false;
}
int ChangeCharByINT(char* num) {
  int tmp = 0;
  int large = strlen(num) - 1;
  if (num[0] != '-') {
    for (int p = (0); p <= (large); p += (1)) tmp = 10 * tmp + (num[p] - '0');
  } else {
    for (int p = (1); p <= (large); p += (1)) tmp = 10 * tmp + (num[p] - '0');
    tmp *= -1;
  }
  return tmp;
}
int r, c, pr, pc, dir, dst, mov, last, f[200], l[200];
char tab[200][200];
int main() {
  scanf("%d%d", &r, &c);
  last = 0;
  for (int rr = (1); rr <= (r); rr += (1)) {
    scanf("%s", &tab[rr]);
    f[rr] = c;
    l[rr] = 1;
  }
  for (int rr = (1); rr <= (r); rr += (1))
    for (int cc = (c); cc >= (1); cc -= (1)) {
      tab[rr][cc] = tab[rr][cc - 1];
      if (tab[rr][cc] == 'W') {
        last = rr;
        if (f[rr] > cc) f[rr] = cc;
        if (l[rr] < cc) l[rr] = cc;
      }
    }
  mov = 0;
  pr = pc = dir = 1;
  while (1) {
    if (dir == 1) {
      dst = 0;
      if (l[pr] > pc) dst = l[pr] - pc;
      if (pr < last && l[pr + 1] > pc + dst) dst = l[pr + 1] - pc;
      mov += dst;
      pc += dst;
      if (pr < last) {
        pr++;
        mov++;
        dir = -1;
      } else
        break;
    }
    if (dir == -1) {
      dst = 0;
      if (f[pr] < pc) dst = pc - f[pr];
      if (pr < last && f[pr + 1] < pc - dst) dst = pc - f[pr + 1];
      mov += dst;
      pc -= dst;
      if (pr < last) {
        pr++;
        mov++;
        dir = 1;
      } else
        break;
    }
  }
  printf("%d", mov);
}
