#include <bits/stdc++.h>
using namespace std;
void start() {}
char dp[200][200];
bool vis[200][200] = {0};
long long int n, m, ans = 0, final = 0;
vector<long long int> frst, last;
void dfsmat(long long int x, long long int y, bool dir) {
  if (x > final) return;
  if (!dir) {
    long long int maxx = max(last[x], last[x + 1]);
    maxx = max(maxx, y);
    ans += maxx - y;
    dfsmat(x + 1, maxx, 1);
  } else {
    long long int minn = min(frst[x], frst[x + 1]);
    minn = min(minn, y);
    ans += y - minn;
    dfsmat(x + 1, minn, 0);
  }
}
void sober() {
  long long int x = 0, a = 0, b = 0, y = 0, sum = 0, k = 0;
  cin >> n >> m;
  frst.resize(n + 2, m + 1), last.resize(n + 2, 0);
  for (long long int i = 1; i < n + 1; i++) {
    for (long long int j = 1; j < m + 1; j++) {
      cin >> dp[i][j];
      if (frst[i] == m + 1 and dp[i][j] == 'W') {
        frst[i] = j;
      }
      if (dp[i][j] == 'W') {
        last[i] = j;
        final = i;
      }
    }
  }
  ans = 0;
  dfsmat(1, 1, 0);
  ans += max(0LL, final - 1);
  cout << ans << "\n";
}
signed main() {
  start();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    sober();
  }
}
