#include <bits/stdc++.h>
using namespace std;
struct state {
  int x, y;
  state() {
    x = 0;
    y = 0;
  }
  state(int xx, int yy) {
    x = xx;
    y = yy;
  }
  bool operator<(const state &b) const {
    return (x < b.x || (x == b.x && y < b.y));
  }
  void operator=(state b) {
    x = b.x;
    y = b.y;
  }
  void out() { cout << x << ' ' << y << '\n'; }
};
int n;
pair<int, int> pr[1000000];
char pole[160][160];
int main() {
  int i, j, k, l, r1, r2, r3, r4, res = 0, cur = 0, m, maxx = -1;
  cin >> n >> m;
  memset(pole, 0, sizeof(pole));
  memset(pr, 0, sizeof(pr));
  for (i = 0; i < n; i++) pr[i].first = 1000000;
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      cin >> pole[i][j];
      if (pole[i][j] == 'W') {
        if (j < pr[i].first) pr[i].first = j;
        if (j >= pr[i].second) pr[i].second = j;
        if (i > maxx) maxx = i;
      }
    }
  }
  if (maxx == -1) {
    printf("0");
    return 0;
  }
  int st = 0;
  for (i = 0; i <= maxx; i++) {
    if (pr[i].first >= 1000000 && pr[i + 1].first >= 1000000) {
      res++;
      continue;
    }
    if (i != maxx) res++;
    if (i % 2 == 0) {
      res += abs(max(pr[i].second, pr[i + 1].second) - st);
      st = max(pr[i].second, pr[i + 1].second);
    } else {
      if (i != maxx)
        res += abs(min(pr[i].first, pr[i + 1].first) - st);
      else
        res += abs(pr[i].first - st);
      st = min(pr[i].first, pr[i + 1].first);
    }
  }
  cout << res;
  return 0;
}
