#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
const int MAXN = 163;
const int INF = 0x3F3F3F3F;
char mat[MAXN][MAXN];
int l[MAXN], r[MAXN];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    l[i] = m - 1, r[i] = 0;
    for (int j = 0; j < m; j++) {
      cin >> mat[i][j];
      if (mat[i][j] == 'W') {
        l[i] = min(l[i], j);
        r[i] = max(r[i], j);
      }
    }
  }
  l[n] = m - 1, r[n] = 0;
  for (int i = 0; i < m; i++) {
    mat[n][i] = 'G';
  }
  int now = 0, dir = 0, next = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (i & 1) {
      next = mat[i][l[i]] == 'W' ? l[i] : now;
      if (mat[i + 1][l[i + 1]] == 'W') {
        next = min(next, l[i + 1]);
      }
      ans += abs(now - next);
      now = next;
    } else {
      next = mat[i][r[i]] == 'W' ? r[i] : now;
      if (mat[i + 1][r[i + 1]] == 'W') {
        next = max(next, r[i + 1]);
      }
      ans += abs(now - next);
      now = next;
    }
  }
  int add = n - 1;
  for (int i = n - 1; i >= 1; i--) {
    bool havew = 0;
    for (int j = 0; j < m; j++) {
      if (mat[i][j] == 'W') {
        havew = 1;
        break;
      }
    }
    if (!havew)
      add--;
    else
      break;
  }
  cout << ans + add << endl;
}
