#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
char board[205][205];
int mn[205], mx[205];
bool cont[205];
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  while (cin >> n >> m) {
    memset(mn, 0x3f, sizeof(mn));
    memset(mx, 0, sizeof(mx));
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        cin >> board[i][j];
        if (board[i][j] == 'W') {
          mn[i] = min(mn[i], j);
          mx[i] = j;
        }
      }
    }
    int en = n;
    while (en && !mx[en]) --en;
    int cnt = 0, cur = 1, nxt;
    for (int i = 1; i <= en; ++i) {
      if (i & 1) {
        assert(cur <= mn[i]);
        nxt = max(mx[i], mx[i + 1]);
        if (nxt > cur) {
          cnt += nxt - cur;
          cur = nxt;
        }
      } else {
        assert(cur >= mx[i]);
        nxt = min(mn[i], mn[i + 1]);
        if (nxt < cur) {
          cnt += cur - nxt;
          cur = nxt;
        }
      }
      ++cnt;
    }
    cout << max(0, cnt - 1) << "\n";
  }
  return 0;
}
